在 Git 中,如何区分分支的第一次提交?
我已经对本地分支进行了多次提交,但我不确定将我当前拥有的内容与分支的起始状态进行比较的最佳方法是什么。我知道如果我的分支有 6 次提交,我可以做类似 git diff HEAD HEAD~6 的事情,但我希望得到一些与提交数量无关的东西。
编辑: 我没有提到这一点:我希望我不必深入日志来获取我分支的提交的哈希值。例如,如果我有 80 次提交,这将不是一项有趣的任务。
另外,假设我分支的原始分支已经发生了一些更改。
I've made several commits to a local branch, but I'm not sure what the best way to diff what I currently have to my branch's starting state. I know I can do something like git diff HEAD HEAD~6
if there's been 6 commits to my branch, but I was hoping for something that was independent of the number of commits.
Edit:
I failed to mention this: I was hoping I wouldn't have to dig through the log to get the hash of the commit I branched from. If I had 80 commits for example, this wouldn't be a fun task.
Also, presume that the original branch I branched from has already had several changes.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您需要使用 git help diff 中描述的三点语法:
这与以下内容相同:
与以下内容相同:
merge-base
命令打印“ best”(最近的)共同祖先,因此上面的命令显示了HEAD
与otherbranch
共同的最近提交到HEAD
。请注意,您可以使用
@{u}
代替otherbranch
来查看自您脱离上游分支以来所做的更改。有关语法的详细信息,请参阅 git help revisions 。You'll want to use the triple dot syntax described in
git help diff
:This is the same as:
which is the same as:
The
merge-base
command prints the "best" (most recent) common ancestor, so the above command shows the difference from the most recent commit thatHEAD
has in common withotherbranch
toHEAD
.Note you can use
@{u}
in place ofotherbranch
to see the changes you made since you diverged from the upstream branch. Seegit help revisions
for details about the syntax.首先,您需要找到您分支的提交。一旦你有了这个,你就可以简单地执行 git diff..HEAD (正如 yasouser 指出的那样)。
First, you need to find the commit you branched from. Once you have that, you can simply do a
git diff <branch-point>..HEAD
(as yasouser pointed out).git diff <您分支的提交的 SHA-1>..HEAD
您可以通过执行
git log
获取分支点的 SHA-1。git diff <SHA-1 of the commit from which you branched>..HEAD
You can get the SHA-1 of your branch point by doing a
git log
.