简体   繁体   中英

git head detached from master

Its really confusing i trying push my all commits to production. But when i push to server 8840f9e pushing this.

My goal is push all my commits to production.

commit d06a8c7(HEAD)

commit e1467b4

commit 0ed15e7

commit 5886ab9

commit 0f8ee01

commit 8840f9e (production/master, master)

tl;dr
You could try git branch tempbranch d06a8c7d9a && git checkout master && git merge tempbranch to get the commit onto your master branch, and then do the push to production.


Usually, git commits are on some branch. Maybe on multiple, but that's not relevant here.
When you usually work, you are supposed to have some branch checked out - yours is called master .
But it can happen that you leave the branch, and create commits of your new changes without telling git on which branch they belong. In that case, git will enter something called a "detached head state".

For example:

git init
touch file.txt
git add file.txt
git commit -m "initial commit"

Creates a file and commits it. Let us modify the file and commit again, so we have two commits. If you now explicitly git checkout HEAD~ , ie if you check out the first commit, you are no longer on the master branch. This is just one example of how to get to that state.

If you now create a new commit, git will warn you:

 $ git checkout HEAD^ Note: checking out 'HEAD^'. 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 performing another checkout. If you want to create a new branch to retain commits you create, you may do so (now or later) by using -b with the checkout command again. Example: git checkout -b <new-branch-name> HEAD is now at 24ebade initial commit

To get the new commits back to some branch, you can do what it recommends you.
Create a new branch which points to your latest commit, using git checkout -b tempBranch for example.

It is possible, that you have some commits on master , that contradict your changes that happened in this detached HEAD state which is now on tempBranch . Because of that, you might need to resolve merge conflicts.

git checkout master
git merge tempbranch

makes sure both your commit histories are merged together into your master branch. After resolving merge conflicts, you are back at a state which you're used to, and can push as usual.
To clean up, since you do not need the temporary branch tempBranch anymore, you can delete it using git branch -d tempbBranch .

  • Create a new temporary branch , say tempcommit
  • Checkout new branch
  • add commit to new branch
  • merge new branch to master

All in one command is like this

git branch tempcommit <commit id> && git checkout master && git merge tempbranch

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