2

I trying to build a git log command to show commits reachable from commit1 but not reachable from a set of other commits (commit2 ...). However I seem to be doing something wrong with a command to exclude those reachable from just one (commit2) using the ^ prefix notation and I hope somebody can show me what I've got wrong.

I'm successfully using the ".." revision range syntax. It correctly returns 2 commits as shown below:

>git log 349ef28..4b58345 --pretty="format:%H"
4b58345764e1527ce150e1b31bb722130e018651
eaf22be216276964d5c07ca9196c6ab48041b046

But when I use the ^ prefix fails, it just lists everything. I expected both to return the same two commit SHAs.

>git log ^349ef28 4b58345 --pretty="format:%H"
4b58345764e1527ce150e1b31bb722130e018651
eaf22be216276964d5c07ca9196c6ab48041b046
349ef283776d6c5374894bcc571267a0bee24fd5
aeb1fd3b65fe9c82bad839bd9f34e0bc2603290d
aef60d126e5ea756ef44cccb43cda28044a560ed
     :

I've tried:

  • Using full SHA
  • Reversing the order of commits on the command line
  • Without any formatting
  • I've even read the documentation (but obviously I've missed something)

What am I doing wrong?


Updated: Replaced image with text as requested.

4
  • 1
    Weird. Looks correct to me. Commented Nov 28, 2024 at 7:34
  • 4
    Would you mind switching that image for text instead? Commented Nov 28, 2024 at 7:42
  • Can you run that with --graph? Commented Nov 28, 2024 at 8:00
  • 2
    Please do not use images for logs: meta.stackoverflow.com/questions/285551/… Commented Nov 28, 2024 at 12:04

1 Answer 1

7

You are using the Windows command line CMD. This beast treats ^ specially (it is some sort of escape character). You have to type it twice for every occurrence where you need one of them:

git log ^^1234abcd 5678ef01

However, the pager, less, does its own terminal emulation, where this special treatment is not needed. For example, to search for the beginning of the next commit, i.e., the word commit at the beginning of a line, type /^commitEnter. Note that we use just one ^. (Then to search for further commits, just type n.)

Sign up to request clarification or add additional context in comments.

3 Comments

wow! good catch, @j6t.
or use quotes: "^1234abcd"
Gosh ... after all these years I did not know that. Thank you! Solved.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.