简体   繁体   中英

GIT: Not lossing changes after branch detached HEAD

I have been working in git submodule and I was ready to push my changes when I got this message:

$ git push
fatal: You are not currently on a branch.
To push the history leading to the current (detached HEAD)
state now, use

    git push origin HEAD:<name-of-remote-branch>

I ran the following command thinking this may fixed:

git checkout master

But I got this message:

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

  2f1b645 my changes

If you want to keep it by creating a new branch, this may be a good time
to do so with:

 git branch <new-branch-name> 2f1b645

Switched to branch 'master'
Your branch is up-to-date with 'origin/master'.

My question to you guys is how can push my changes to master?

Just cherry-pick that commit on your master branch:

git cherry-pick 2f1b645

The problem you had was that you were not on a local branch when you committed that changes.

By the way, you could also have rebased or merged your commit.

git rebase 2f1b645

or

git merge 2f1b645

Probably to rebase it would have been the nicest solution, but since I'm not 100 percent sure what you had checked out, the cherry pick is the safest way to go.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM