I was not currently on any branch when I commited my changes. I didn't really notice the message and checked out another branch.
How can I retrieve my changes? I can't merge or checkout, since there is no branch to merge from.
Checkout an Existing Branch Generally, Git won't let you checkout another branch unless your working directory is clean, because you would lose any working directory changes that aren't committed.
when you switch to a branch without committing changes in the old branch, git tries to merge the changes to the files in the new branch. If merging is done without any conflict, swithing branches will be successful and you can see the changes in the new branch.
The "checkout" command can switch the currently active branch - but it can also be used to restore files. The most common use case for "checkout" is when you want to switch to a different branch, making it the new HEAD branch.
The git checkout command lets you navigate between the branches created by git branch . Checking out a branch updates the files in the working directory to match the version stored in that branch, and it tells Git to record all new commits on that branch.
You can use git reflog
to get the commit hash of the commit that you did while in "no branch" ( a detached HEAD) and merge that in to the branch that you are currently in ( master maybe)
Something like git merge HEAD@{1}
You can also git rebase -i
and "pick" the commit you want from the reflog.
I was in a similar state after committing some work:
Lilith:Manager KelSolaar$ git status
Not currently on any branch.
I issued a git log to see my last commit hash:
Lilith:Manager KelSolaar$ git log
commit 49984303037e970d637161c3154b7fd7d6ae3a43 Author: KelSolaar Date: Wed Oct 5 22:41:31 2011 +0100
Introduce new "QObject" components category and rename existing ones to "Def
I then checked out my master branch:
Lilith:Manager KelSolaar$ git checkout master
Previous HEAD position was 4998430... Introduce new "QObject" components categorie and rename exising ones to "Default" and "QWidget".
Switched to branch 'master'
And I finally merged using the commit hash:
Lilith:Manager KelSolaar$ git merge 49984303037e970d637161
Updating 141bc69..4998430
Fast-forward
src/manager/component.py | 2 +-
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With