Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Warning: you are leaving 1 commit behind, not connected to any of your branches

EGit strikes again. I made the mistake of trying to switch to a different branch in EGit and it somehow messed up and checked out no branch. I then made a commit to this non-branch, and then when I realized I wasn't tracking the right branch, I ran the following:

$ git checkout issue2 Warning: you are leaving 1 commit behind, not connected to any of your branches:      bada553d My commit message  If you want to keep them by creating a new branch, this may be a good time to do so with:      git branch new_branch_name ....  Branch issue2 set up to track remote branch issue2 from origin. Switched to a new branch issue2.  

Now that I've botched things, how do I associate that commit with my current branch? I'm not interested in creating a brand new branch, I just want to pull that commit into my branch, issue2.

like image 875
Naftuli Kay Avatar asked Jan 16 '13 19:01

Naftuli Kay


People also ask

Do you have to commit before changing branches?

You may switch branches with uncommitted changes in the work-tree if and only if said switching does not require clobbering those changes.

Can I commit in a detached head state?

You are in 'detached HEAD' state. You can look around, make experimental changes and commit them, and you can discard any commits you make in this state without impacting any branches by switching back to a branch.

How do I commit to all branches?

If you use git branches a lot, you'll often push each branch after each commit. Instead of pushing every single branch you can do git push --all origin . This will push all commits of all branches to origin.


1 Answers

you can git cherry-pick bada553d if it's just the one commit.

You can also reference anywhere you've been by using the reflog:

git reflog 

then use one of those commits:

git checkout -b temp HEAD@{3} 

to checkout and make a branch temp from where your current commit was 3 "times" ago. It's a bread crumb of where you used to be.

like image 183
Adam Dymitruk Avatar answered Sep 21 '22 03:09

Adam Dymitruk