如何在Git的分支上获取更改 [英] How to get the changes on a branch in Git

查看:115
本文介绍了如何在Git的分支上获取更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

自分支从当前分支分支以来,在分支上获取提交日志的最佳方法是什么?到目前为止,我的解决方案是:

$ g $ log $ git merge-base HEAD分支分支
code>

表示 git diff A ... B 相当于 git diff $(git-merge-base AB)B 。另一方面, git-rev的文档-parse 表示 r1 ... r2 定义为 r1 r2 - 不是$(git merge-base --all r1 r2)



为什么这些不同?注意, git diff HEAD ... branch 给了我想要的差异,但相应的git log命令给了我比我想要的更多的结果。



在图片中,假设:

 
x --- y --- z ---分支
/
--- a --- b --- c --- d --- e --- HEAD

我想得到一个包含提交x,y,z的日志。




  • git diff HEAD ... branch 给这些提交

  • 然而, git log HEAD ... branch y,z,c,d,e。


解决方案

A ... B git-rev-parse 定义它的方式。 git-log需要一个修订列表。 git-diff 不包含修订列表 - 它需要一个或两个修订版,并定义了 A ... B 语法来表示它在 git-diff 手册页中的定义。如果 git-diff 未明确定义 A ... B ,那么该语法将无效。请注意, git-rev-parse 手册页在指定范围部分描述了 A ... B ,并且只有在修订范围有效的情况下(即,当需要修订列表时),该部分中的所有内容才有效。



要获取仅包含x,y,和z,尝试 git log HEAD..branch (两个点,而不是三个)。这与 git log branch - 不是HEAD 相同,并且表示分支上不在HEAD上的所有提交。


What is the best way to get a log of commits on a branch since the time it was branched from the current branch? My solution so far is:

git log $(git merge-base HEAD branch)..branch

The documentation for git-diff indicates that git diff A...B is equivalent to git diff $(git-merge-base A B) B. On the other hand, the documentation for git-rev-parse indicates that r1...r2 is defined as r1 r2 --not $(git merge-base --all r1 r2).

Why are these different? Note that git diff HEAD...branch gives me the diffs I want, but the corresponding git log command gives me more than what I want.

In pictures, suppose this:

         x---y---z---branch
        /
---a---b---c---d---e---HEAD

I would like to get a log containing commits x, y, z.

  • git diff HEAD...branch gives these commits
  • however, git log HEAD...branch gives x, y, z, c, d, e.

解决方案

In the context of a revision list, A...B is how git-rev-parse defines it. git-log takes a revision list. git-diff does not take a list of revisions - it takes one or two revisions, and has defined the A...B syntax to mean how it's defined in the git-diff manpage. If git-diff did not explicitly define A...B, then that syntax would be invalid. Note that the git-rev-parse manpage describes A...B in the "Specifying Ranges" section, and everything in that section is only valid in situations where a revision range is valid (i.e. when a revision list is desired).

To get a log containing just x, y, and z, try git log HEAD..branch (two dots, not three). This is identical to git log branch --not HEAD, and means all commits on branch that aren't on HEAD.

这篇关于如何在Git的分支上获取更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆