Search code examples
gitgit-branchgit-refloggit-history

Git get history of branches that i was in


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:

  • b-1-1
  • b-2
  • b-1-1
  • b-1
  • master

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.


Solution

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

    • checkout the existing branch branch (git checkout abc)
    • see its log (git log -n 10)
    • checkout another existing branch xyz (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.