在 Git 中,如何区分分支的第一次提交?

发布于 2024-11-16 03:41:53 字数 231 浏览 2 评论 0原文

我已经对本地分支进行了多次提交,但我不确定将我当前拥有的内容与分支的起始状态进行比较的最佳方法是什么。我知道如果我的分支有 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 技术交流群。

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

发布评论

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

评论(3

彼岸花似海 2024-11-23 03:41:54

您需要使用 git help diff 中描述的三点语法:

git diff otherbranch...

这与以下内容相同:

git diff otherbranch...HEAD

与以下内容相同:

git diff $(git merge-base otherbranch HEAD) HEAD

merge-base 命令打印“ best”(最近的)共同祖先,因此上面的命令显示了 HEADotherbranch 共同的最近提交到 HEAD

请注意,您可以使用 @{u} 代替 otherbranch 来查看自您脱离上游分支以来所做的更改。有关语法的详细信息,请参阅 git help revisions 。

You'll want to use the triple dot syntax described in git help diff:

git diff otherbranch...

This is the same as:

git diff otherbranch...HEAD

which is the same as:

git diff $(git merge-base otherbranch HEAD) HEAD

The merge-base command prints the "best" (most recent) common ancestor, so the above command shows the difference from the most recent commit that HEAD has in common with otherbranch to HEAD.

Note you can use @{u} in place of otherbranch to see the changes you made since you diverged from the upstream branch. See git help revisions for details about the syntax.

淡淡離愁欲言轉身 2024-11-23 03:41:54

首先,您需要找到您分支的提交。一旦你有了这个,你就可以简单地执行 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).

潇烟暮雨 2024-11-23 03:41:54

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.

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