2

I'm working on a large project that mixes C++ code and HTML template files.

I learnt today that I was supposed to merge the changes I made to the C++ files (and only those) on another branch, but as you might guess: I can't remember all the commits I did.

Is there a way for me to search, through the git history, all the commits that match all these criteria ?

  • Are written by me
  • Are located between commit A and commit B
  • Contain changes to .cpp, .c or .h files (those are located in a particular sub-directory if that helps).

2 Answers 2

7

I finally figured out how to do that:

To search commits matching a particular author, you can use the --author option:

git log --author=ereOn 

To search commits from commit A to B, use the A..B form:

git log 9223253452..HEAD 

Finally, to only care about commits that concern specific files or paths:

git log -- path_or_file 

The -- is used to indicate the end of the optional arguments and the beginning of the positional arguments.

All combined, that gives:

git log --author=ereOn 9223a6d916c034345..HEAD -- cpp_folder/* 

Which works like a charm :)

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

4 Comments

You should accept your own answer if it's the best answer that's been posted!
@WillVousden: Can only do that in 2 days :)
could you explain this a little?
@JKirchartz: Sure. I edited my answer to add the details about each option.
1

Look into git log, running git log --stat will show a lot of the details you're looking for, you could search by piping it to grep like git log --stat | grep searchterm, but that will only give you lines with your search term.

You can limit it to author with this flag --author "your name"

On my machine git log's output is run through vim/less, with that you can search the log with vim's search command like /searchterm, to find all occurrences of the term, to go to the next one hit n to go to the previous hit N

Check out the man page for git log

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.