如何单步执行 git 存储库?
我正在尝试了解一个项目,使用 gitk 来查看它的演变会有所帮助。我所做的就是检查第一个提交,理解代码,运行测试,转到下一个提交并重复。我当前的工作流程是通过哈希值签出提交
git checkout 79cd6
,但我想要的是另一个分支,我可以在其中执行自己的更改,并允许我合并来自主分支的提交,但不需要找到提交哈希值。理想化的工作流程:
git checkout -b <newbranch> <first commit id of master>
git <command to move head of current branch to next commit of master>
I am trying to understand a project, it helps to look at its evolution by using gitk. What I do is checkout the first commit, understand code, run tests, go to next commit and repeat. My current workflow is to checkout the commit through its hash
git checkout 79cd6
But what I would like is another branch where I can perform my own changes, and allows me to merge commits from the master branch, but without the need to find the commit hash. Idealized workflow:
git checkout -b <newbranch> <first commit id of master>
git <command to move head of current branch to next commit of master>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我知道这是一个有点老的问题,但我想做同样的事情并找到答案,所以我想我会分享。
在一个窗口中执行此操作。它将从您的初始提交开始,并在您每次按回车键时前进一次。然后在不同的 shell 中进行测试等。
它将与线性历史完美配合,但我不太确定它将如何处理合并等。我确信这是合理的,但您的里程可能会有所不同。
I know this is a bit of an old question, but I wanted to do the same thing and found an answer so I figured I'd share.
do this in one window. It will start with your initial commit, and advance once each time you hit enter. Then do your testing etc. in a different shell.
It'll work perfectly with a linear history, but I'm not quite sure how it will handle merges and such. I'm sure it'll be reasonable, but your mileage might vary a bit.
将其保存为
~/bin/git-next
或路径中的其他位置:这将检查当前修订版本的第一个子版本。
对于大型回购来说,它会非常慢,但它可以完成工作。
您可以修改它以根据需要处理分支。
Save this as
~/bin/git-next
or somewhere else in your path:This will check out the first child of the current revision.
It will be very slow on a big repo but it will do the job.
You can modify this to handle your branching as needed.
你可以写一个小 shell 脚本。一个脚本将运行 git log --pretty=oneline | awk '{print $1;}'。第二个脚本(称之为
step
或其他)将使用head
、tail
、wc -l
。然后用tail
读取文件的最后一行,找出文件中有多少行,并从文件中删除最后一行。丑陋,当然,但它可以完成工作。 :) (如果你想不那么难看,它可以使用 truncate(1) 来截断文件的最后一行,而不是总是创建新的临时文件。)You could write a little shell script. One script would run
git log --pretty=oneline | awk '{print $1;}'
. The second script (call itstep
or something) would usehead
,tail
,wc -l
. Then read the last line of the file withtail
, find out how many lines are in the file, and remove the last line from the file. Ugly, sure, but it'd do the job. :) (If you wanted to be a little less ugly, it could usetruncate(1)
to just chop off the last line of the file, rather than always making new temporary files.)我想要一种简单的方法来逐步完成分支中的提交以进行代码审查/演示。这是我想出的让它自动化的小脚本。将以下内容放入文件中,例如
git_step
并像这样运行它:git_step d17dacce8b13b2ad454003da7cbd670a06c41437
也可以作为 要点在这里。
I wanted an easy way to step through commits in a branch for code review/demo. This is the little script I came up with to automate it. Drop the following in a file, say,
git_step
and run it like so:git_step d17dacce8b13b2ad454003da7cbd670a06c41437
Also available as a gist here.