简体   繁体   English

如何确定 git 修复提交的目标提交?

[英]How do I determine target commit of a git fixup commit?

After creating fixup git commits, is there are way to show or cat-file or something the commit and figure out it's target commit?在创建修复 git 提交后,有没有办法显示或 cat-file 或提交的东西并找出它的目标提交? Specifically I don't want to have to guess and check all the time with rebase -i to find out that my rebase target is sufficiently back far enough in history.具体来说,我不想一直猜测和检查 rebase -i 来发现我的 rebase 目标在历史上已经足够远了。

I'll assume you mean a commit generated with git commit --fixup .我假设您的意思是使用git commit --fixup生成的提交。

Git uses the first line of the fixup commit's commit message, which looks similar to this: Git 使用 fixup commit 的提交消息的第一行,类似于以下内容:

fixup! Remove some foos from bars

To find this commit, you can use the exact same method that Git itself will use: it searches let Git search back in the history until it finds a commit that begins with the text after the fixup!要查找此提交,您可以 使用与 Git 本身将使用的完全相同的方法:它搜索 让 Git 在历史记录中搜索,直到找到以修复后的文本开头的提交fixup! token.令牌。 The magic command is:魔术命令是:

git show 'HEAD^{/Remove some foos}'

This will search back beginning at HEAD and show the first commit matching the text in the braces (sans / , which is an instruction for search the following text ).这将从HEAD开始搜索并显示与大括号中的文本匹配的第一个提交(sans / ,这是搜索以下文本的指令)。


EDIT: I was really confused when I tested stuff in Windows CMD (in particular, its treatment of ^ ).编辑:当我在 Windows CMD 中测试东西时,我真的很困惑(特别是它对^的处理)。 As @torek points out in the comments, ^{/xyz} syntax does a match of the given regular expression on the entire commit message.正如@torek 在评论中指出的那样, ^{/xyz}语法在整个提交消息上匹配给定的正则表达式。 Therefore, it is necessary to anchor the regular expression at the beginning of the text.因此,有必要将正则表达式锚定在文本的开头。 The correct command is:正确的命令是:

git show 'HEAD^{/^Remove some foos}'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM