Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

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

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...