分享 逆向查看 Git repository commits history

willmouse · January 10, 2015 · Last by chanshunli replied at April 21, 2015 · 1782 hits
[alias]

# Go to the first commit
first = "!git checkout `(git log --oneline --reverse | head -n 1 | awk '{print $1}')`"

# Go to the last commit
last = checkout master

# Go to the next commit
next = "!git checkout $(git log --oneline --reverse --ancestry-path 'HEAD..master' | head -n 1 | awk '{print $1}')"

# Go to the previous commit
pre = checkout 'HEAD^'

将上面 4 个 alias 复制到~/.gitconfig[alias]后面即可。

git first回到第一个 commit 后,便可使用git next检出下一个 commit 到本地目录。

如果你希望可以在编辑器里查看每次历史提交后的文件内容,这个能派上用场。

PS:上面的 alias 假定 upstream 的分支名为 master,如果不是的话需要手动修改。

另外git next只会检出从第一个 commit 开始的直接祖先,如果遇到 diverge 的情况,将会检出相应分支与主分支合并后的 commit。

Unknow user #1 April 21, 2015

good job :)

You need to Sign in before reply, if you don't have an account, please Sign up first.