ereOn
ereOn

Reputation: 55726

Search for particular commits

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 ?

Upvotes: 2

Views: 122

Answers (2)

ereOn
ereOn

Reputation: 55726

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 :)

Upvotes: 7

JKirchartz
JKirchartz

Reputation: 18022

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

Upvotes: 1

Related Questions