Reputation: 433
I need to see the history of branches that i was using. For example i have 4 branches: master, b-1, b-2, b-1-1. Thе branch "b-1-1" is child of branch "b-1". First i was at master branch, then at branch b-1, then at branch b-1-1 , then at branch b-2, then again at b-1-1. The history of my used branches would look like this:
Is it possible to do so in git? If yes, then how? I have tried to check the git log but it is not what i am searching for.
Upvotes: 11
Views: 9822
Reputation: 21908
Take a look at git reflog
to inspect the history of HEAD
positions.
There's also git reflog <branch>
for the history of a specific branch.
Check documentation here.
(Bonus)
If useful in your context, you can also craft an alias to extract them by using both the @{-<n>}
construct and the name-rev
command (which is roughly the reverse of rev-parse
):
$ git config alias.last '!f() { for i in $(seq 1 $1); do git name-rev --name-only --exclude=refs/tags/\* @{-$i}; done; }; f'
$ git last 3
# outputs the 3 last checked out branches
Upvotes: 17
Reputation: 8046
This invocation of git reflog
with some grep
filtering seems to be working for me:
git reflog | grep checkout | grep -o 'to .*$' | grep -o ' .*$' | less
git reflog | Select-String 'checkout' | ForEach-Object { $_ -replace '^.*to ', '' } | Out-Host -Paging
For example:
b2
master
b1
master
b2
b1
b2
...
Upvotes: 6
Reputation: 42431
I don't think you can see which branch were checked out and in which order in a sense that you've formulated in the question . Branch is a pointer and this pointer can change only if you do commit.
For example, if you:
git checkout abc
)git log -n 10
)git checkout xyz
)Then git won't remember that you were checking out the abc
branch
Having said that, you can see the commits that you've done during, say last 3 days with this command:
git log --since="3 days ago" --author=<HERE_COMES_YOUR_NAME_IN_GIT> --all
This --since
parameter can be really flexible, 1 day ago
, exact time, 1 week ago
are all possible values, check out the documentation and also this SO thread
Another interesting option is using (in its the most basic form): git for-each-ref --sort=-committerdate refs/heads/
This command will print all commits in all branches in the descending order. There is already thread in SO about this and it provides way more options of possible usage of this command than I can do so please check that out as well.
Upvotes: 2