Skip to content

Instantly share code, notes, and snippets.

@wendao
Last active December 22, 2015 00:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wendao/6391751 to your computer and use it in GitHub Desktop.
Save wendao/6391751 to your computer and use it in GitHub Desktop.
git command line
git commit #本地操作,可多次进行
git branch newbranch #建立一个新的branch
git checkout newbranch #切换branch
git merge oldbranch #合并另一个分支
git rebase oldbranch #直接跳转过去(和merge区别:改变父亲)
git revert HEAD^
git reset --hard HEAD #放弃最近未commit的修改
#恢复一个错误的push,强制覆盖history,需要赶在别人fetch/pull之前
git reset HEAD^ --hard
git push [github] -f
#从别的repo merge
git fetch origin
git merge origin/an-other-branch
#merge但是不commit
git merge [branch] --no-commit --no-ff
#检查历史上commit的文件变动
git log --name-status
git log --name-only
git log --stat
Configure your new merge tool:
git config --global mergetool.sublime.cmd "subl -w \$MERGED"
git config --global mergetool.sublime.trustExitCode false
git config --global merge.tool sublime
And pro re nata:
git mergetool -y
##
git config merge.renameLimit 999999
So let's suppose maint has had 5 changes applied, and one of those (maint~3) is not to be merged back into master, although all the others should be. You do this in three stages: actually merge everything before that one, tell git to mark maint~3 as merged even when it isn't, and then merge the rest. The magic is:
bash <master>$ git merge maint~4
bash <master>$ git merge -s ours maint~3
bash <master>$ git merge maint
The first command merges everything before your troublesome maint commit onto master. The default merge log message will explain you're merging "branch 'maint' (early part)".
The second command merges the troublesome maint~3 commit, but the "-s ours" option tells git to use a special "merge strategy" which, in fact, works by simply keeping the tree you are merging into and ignoring the commit(s) you are merging completely. But it does still make a new merge commit with HEAD and maint~3 as the parents, so the revision graph now says that maint~3 is merged. So in fact you probably want to use the -m option to 'git merge' as well, to explain that that maint~3 commit is actually being ignored!
The final command simply merges the rest of maint (maint~2..maint) into master so that you're all synced up again.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment