Page tree

Versions Compared


  • This line was added.
  • This line was removed.
  • Formatting was changed.


git merge-basegit merge-base master develop 
git reset --hard  
git show  
git reflog reflog是git用来记录引用变化的一种机制,比如记录分支的变化或者是HEAD引用的变化。git reflog命令可用于
找回因不当使用git reset 而丢失的commit. 先跑git reflog, 结果列表中的HEAD@{1}就是前一次HEAD所在位置,
然后 git merge <commit_hash> (或git reset --hard <commit_hash>)可以恢复。
参考 restoring lost commits
git merge ... -s oursgit merge branch1 -s ours合并,但不引入源分支的任何change,实际上是一个dummy merge
git merge <branch> -s recursive -X theirs/oursgit merge feature/0.6/dummy_feature_2 -s recursive -X theirs合并分支,自动解决冲突,如果不能解决的,用theirs/ours指定用哪一边的改动
git show-branch --remotes --listgit show-branch --list | grep deploy列出所有分支,还可以跟grep命令结合用于查找分支
git merge --no-commit  
git update-index --[no-]assume-unchanged  

git push origin --delete <branch>

git merge --abort
git merge --no-ff  
git revert -m 1 commit_hash

See chapter 4 in the git book and the original post by Linus Torvalds.

To undo a merge that was already pushed:


git cat-file -p <hash>git cat-file -p 0ad9c330014dd375e4c560f725bf8895c74739c7显示文件的内容
git show HEAD^1

git show HEAD^2

git show HEAD^^2

git log -S'source_code_to_be_searched'git log -S't_vplus_member_with_location'搜索包含指定源代码片段的提交
git log --pretty=format:"%h%x09%an%x09%ad%x09%s" 一行显示commit log,包含hash, author, date, message等信息
git log --oneline | grep "Merge branch" | grep "'develop' " 搜索从develop到其他分支的合并
git log --no-merges --stat --author="Pattern" --name-only --pretty=format:"" | sort -u
git log --author="<authorname>" --oneline --shortstat

git log --author="jacob.wu" --pretty=tformat: --numstat

git blame --reverse START..END filename
git blame --reverse aefdcd..HEAD /path/filename

可用于找出谁删除了某一行代码,先要找到某个commit包含你想追踪的代码,把这个commit作为START;也可以用git log -S'code'达到同样目的,但git log -S'code'可能会找到很多重复的代码。

Walk history forward instead of backward. Instead of showing the revision in which a line appeared, this shows the last revision in which a line has existed. This requires a range of revision like START..END where the path to blame exists in START.

git gc --prune=now

git fetch -p

 清除失效的本地remote tracking分支
git archive --format zip --output "" master 参考
$ git --no-pager log --author="tanke.wyj" --oneline --stat=400 --since=6.month
 > /d/Dev/stats.txt