分享 逆向查看 Git repository commits history

willmouse · 2015年01月10日 · 最后由 chanshunli 回复于 2015年04月21日 · 1779 次阅读
[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。

匿名 #1 2015年04月21日

good job :)

需要 登录 后方可回复, 如果你还没有账号请 注册新账号