如何单步执行 git 存储库?

发布于 2024-09-10 13:48:37 字数 380 浏览 2 评论 0原文

我正在尝试了解一个项目,使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

纵情客 2024-09-17 13:48:37

我知道这是一个有点老的问题,但我想做同样的事情并找到答案,所以我想我会分享。

for commit in $(git rev-list master --reverse)
do
    git checkout $commit
    read
done

在一个窗口中执行此操作。它将从您的初始提交开始,并在您每次按回车键时前进一次。然后在不同的 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.

for commit in $(git rev-list master --reverse)
do
    git checkout $commit
    read
done

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.

苍景流年 2024-09-17 13:48:37

将其保存为 ~/bin/git-next 或路径中的其他位置:

#!/bin/bash
git co $(git rev-list --children --all | awk "/^$(git rev-parse @\{0})/ { print \$2; }")

这将检查当前修订版本的第一个子版本。

对于大型回购来说,它会非常慢,但它可以完成工作。

您可以修改它以根据需要处理分支。

Save this as ~/bin/git-next or somewhere else in your path:

#!/bin/bash
git co $(git rev-list --children --all | awk "/^$(git rev-parse @\{0})/ { print \$2; }")

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.

一笔一画续写前缘 2024-09-17 13:48:37

你可以写一个小 shell 脚本。一个脚本将运行 git log --pretty=oneline | awk '{print $1;}'。第二个脚本(称之为step或其他)将使用headtailwc -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 it step or something) would use head, tail, wc -l. Then read the last line of the file with tail, 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 use truncate(1) to just chop off the last line of the file, rather than always making new temporary files.)

驱逐舰岛风号 2024-09-17 13:48:37

我想要一种简单的方法来逐步完成分支中的提交以进行代码审查/演示。这是我想出的让它自动化的小脚本。将以下内容放入文件中,例如 git_step 并像这样运行它: git_step d17dacce8b13b2ad454003da7cbd670a06c41437

#!/bin/bash

BASE_REV=${BASE_REV:-$1};
current_branch=$(git branch | grep '^*' | awk '{print $2}');

for rev in $(git rev-list ${BASE_REV}..HEAD | tail -r); do
    git checkout $rev;
    LESS='RSX' git show -p $rev;
done;

git checkout ${current_branch};

也可以作为 要点在这里

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

#!/bin/bash

BASE_REV=${BASE_REV:-$1};
current_branch=$(git branch | grep '^*' | awk '{print $2}');

for rev in $(git rev-list ${BASE_REV}..HEAD | tail -r); do
    git checkout $rev;
    LESS='RSX' git show -p $rev;
done;

git checkout ${current_branch};

Also available as a gist here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文