Which git branch was I only on?

My workflow often consists of the following elements:

  • works in a long term feature branch (call it "A")
  • checking out the master and creating a patch branch (let's call it "B")
  • pushing my fix
  • Then I forget which branch I was working with before ...

Is there any git history that will show me that the thing I was working on before was branch A?

+3


source to share


4 answers


Try:

git reflog

      



which will list all your recent actions that changed something, so you can check, reinstall, pull, push, etc.

Also it includes all the commit ids, for example if you made a dozen commit --amend

you can go back to one in the middle.

+6


source


As stated by gitrevisions , the syntax @{-number}

refers to the branch marked back by the branch. This uses reflogs, specifically reflog for HEAD

; see Duncan's answer .



(In your specific example, you would like to @{-1}

. For, git checkout

you can shorten it like git checkout -

, but that only works for git checkout

.)

+2


source


Try:

git branch --sort=-committerdate

      

or

git for-each-ref --sort=-committerdate refs/heads/

      

0


source


git checkout -

      

go to previously used branch

I also set this alias, which prints the last 10 branches I worked on:

[alias]
    recent = for-each-ref --count=10 --sort=-committerdate refs/heads/ --format='%(refname:short) %(committerdate:relative)'

      

0


source







All Articles