Let's say I created a new branch my_experiment
from master
and made several commits to my_experiment
. If I do a git log
when on my_experiment
, I see the commits made to this branch, but also the commits made to master
before the my_experiments
branch was created.
I would find it very useful to see the history of all commits to the my_experiments
branch until it hits the creation of that branch - effectively a true history of just that branch. Otherwise it's not clear to me when looking through the log whether the commits were on the my_experiments
branch or not.
Is there a way to do this with Git?
I think an option for your purposes is
git log --oneline --decorate
. This lets you know the checked commit, and the top commits for each branch that you have in your story line. By doing this, you have a nice view on the structure of your repo and the commits associated to a specific branch. I think reading this might help.You can use a range to do that.
If you've checked out your
my_experiment
branch. This will compare wheremaster
is at toHEAD
(the tip ofmy_experiment
).The
git merge-base
command can be used to find a common ancestor. So if my_experiment has not been merged into master yet and my_experiment was created from master you could:Note: if you limit that log to the last n commit (last 3 commits for instance, git log -3), make sure to put a space between 'n' and your branch:
Before Git 2.1 (August 2014), this mistake:
git log -3master..
would actually show you the last 3 commits of the current branch (heremy_experiment
), ignoring themaster
limit (meaning ifmy_experiment
contains only one commit, 3 would still be listed, 2 of them frommaster
)See commit e3fa568 by Junio C Hamano (
gitster
):revision: parse "
git log -<count>
" more carefully