-
Notifications
You must be signed in to change notification settings - Fork 17
Git
use git config -l can show all the configuration of your git.
- set
git config --global http.proxy http://10.22.98.21:8080- remove
git config --global (or --system or --local) --unset http.proxy- remove all
git config --global (or --system or --local) --unset-all http.proxyHTTP URL:
git config --global http.proxy socks5://127.0.0.1:1080如果使用的是 git URL:
vim ~/.ssh/config
Host github.com
ProxyCommand connect -H 127.0.0.1:1080 %h %p参考自: https://gist.github.com/laispace/666dd7b27e9116faece6
刚才一次误操作仍然心有余悸,本想图省事直接在网页上为blog的post branch增加一个文件夹和一个markdown文档,结果不知怎么搞得合并到主gh-pages分支上去了。结果主分支一下子空了许多。立刻掏出命令行,找回之。
首先需要知道的是,你想回滚到哪一个提交版本?
如图所示,右边那串字符就是你的commits id了。复制你要回滚的版本id。 然后输入以下命令:
git reset --hard <tag/branch/commit id>你会长舒一口气,至少硬盘上看,文件都回来了。 然后你将这些修改重新commit覆盖服务器端版本即可。
需要注意的是:本地branch为A,服务器端branch为B,请问如何正确的push?
git push origin A:B这个冒号,可以理解为to的意思,from A to B.
首先要先确定一下是否建立了主repo的远程源:
git remote -v如果里面只能看到你自己的两个源(fetch 和 push),那就需要添加主repo的源:
git remote add upstream URL
git remote -v然后你就能看到upstream了。
如果想与主repo合并:
git fetch upstream
git merge upstream/masterGithub 上常常有很多非常好的工具,如检测内存泄漏的,单元测试的。如何将这些工具引入到自己的 repo 目录里呢?
下面以 Catch(C++ 单元测试框架) 为例:
- 添加submodule:
git submodule add git@github.com:philsquared/Catch.git- 更新submodule:
# should init
git submodule update --init
git submodule update- 查看状态:
git submodule status- 更改URL
# Modify your .gitmodule file to use the new URL
git submodule sync情景浮现:Cpp-Primer之前的章节被发现有Bug,可是我正在进行第七章的撰写,我不希望把这个半成品发给 @Mooophy,只想pull request给他Bug的修改。
# 新建一个branch来缓存origin repo
git checkout -b upstream origin/master
# 只截取某一个commit,cherry-pick,真是个好名字
git cherry-pick <SHA hash of commit>
# 推送到origin repo就行了
git push origin upstream当然,这几步其实都是在自己的fork内"演练"。你还需要在Github上点一下 pull request 按钮。然后万事大吉啦。
git push origin :del_branch_name由于经常在Windows和Mac上切换,两个系统的行尾空白符却不同意,造成很多不必要的diff,去掉这该死的差别:
git stripspace < README.md有时候会出现不想commit的东西给commit了,尤其是喜欢用git commit -am的人。如何回退?
git reset --soft HEAD~1
# 可以重新调整
# 如果你想直接用上次的log,可以这样:
git commit -c ORIG_HEAD
# 如果你连log都要改,请使用常规的commitgit remote set-url origin git://new.url.here这个可能会有一个后遗症,就是修改后,再 pull 的时候可能会出现 fatal: refusing to merge unrelated histories 的错误。
此时应该加上 --allow-unrelated-histories,如下所示:
git pull origin master --allow-unrelated-historiesgit diff --name-only --diff-filter=Ugit reset --hard <old-commit-id>
git push -f origin branchUsing this is dangerous in a collaborative environment: you're rewriting history.
- 看单个文件的全部 diff:
git log --full-diff -p your_file_path- 看最后两个历史 Commits 的 diff:
git log -p -2see more at: http://git-scm.com/book/en/v2/Git-Basics-Viewing-the-Commit-History
git config --global core.autocrlf input
# Configure Git on OS X or Linux to properly handle line endings
git config --global core.autocrlf true
# Configure Git on Windows to properly handle line endings参考:https://help.github.com/articles/dealing-with-line-endings/#platform-all
git add --force my/ignore/file.foogit checkout -b test origin/testmkdir foo.git
cd foo.git
git init --bare
chown -R git:git .