Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
254 views
in Technique[技术] by (71.8m points)

git log - git log range exclude ancestors of multiple base refs

I often use git log <options> BASE..TARGET to show a range of commits.

What this does, based on my previous experience and understanding:

  • Include TARGET and all its ancestors.
  • Exclude BASE and all its ancestors, even if they are ancestors of TARGET.

Sometimes I would like to achieve the following instead:

  • Include TARGET and all its ancestors.
  • Exclude BASE_0 and all its ancestors, even if they are ancestors of TARGET.
  • Exclude BASE_1 and all its ancestors, even if they are ancestors of TARGET.
  • Exclude BASE_2 and all its ancestors, even if they are ancestors of TARGET.
  • ...

A typical use case would be to find commits that are in (= ancestors of) a given feature branch, but are neither in (= ancestors of) master nor a specific other feature branch.

Obviously, the range A..B syntax won't cut it here. Instead, there would need to be a parameter like --exclude-ancestors-of=A_0,A_1,A_2, with a syntax that allows multiple refs.

Is this possible somehow?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

As jthill commented, you can express this with:

git log TARGET ^BASE_0 ^BASE_1 ^BASE_2

(these can go in any order). If you have a lot of negated references—the ^BASE_number expressions above are negated references—you can simplify typing a bit with:

git log TARGET --not BASE_0 BASE_1 BASE_2

The --not tells Git all subsequent specifiers are to be negated. A second --not negates the negation, going back to positive references, so you can—a bit pointlessly for this example—write:

git log --not BASE_0 BASE_1 BASE_2 --not TARGET

as well.

There are many ways to express revisions and revision ranges in Git; see the gitrevisions documentation (or git help revisions) for a reasonably complete list. Note that the two-dot and three-dot syntaxes may take on different meanings in several commands, though. The git diff command is the most significant example of this. Consult each specific Git command's manual page to see if it has special meaning to that command, and if so, what the meaning is.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...