使用git我做了这样的东西

git clone
git checkout {a rev number tree rev before} (here I started to be in a detached head state)
//hacking
git commit
//hacking
git commit
(some commit where made on origin/master)
git pull (which does complete because there was some error due to the fact that I'm no more on master)

因为它告诉我,当我处于超然的头脑状态时,我仍然可以做出承诺,我这样做了。 但现在我想合并分离的head分支和本地master分支,然后将我的一堆更改推到origin/master。

所以我的问题是我如何将主分支与我的实际状态(分离头)合并


当前回答

也许不是最好的解决方案,(将重写历史),但你也可以做git重置——hard <散列的分离头提交>。

其他回答

在你所在的位置创建一个分支,然后切换到master并合并:

git branch my-temporary-work
git checkout master
git merge my-temporary-work

或者,您可以在分支上选择commit-id。

<commit-id>在分离head状态

Git checkout master

Git cherry-pick <commit-id>

没有临时分支,没有合并。

你可以使用git merge <commit-number>或者git cherry-pick <commit> <commit>…

正如Ryan Stewart所建议的,你也可以从当前的HEAD创建一个分支:

git branch brand-name

或者只是一个标签:

git tag tag-name

你可以这样做。

# Create temporary branch for your detached head
git branch tmp

# Go to master
git checkout master

# Merge in commits from previously detached head
git merge tmp

# Delete temporary branch
git branch -d tmp

更简单的是

git checkout master
git merge HEAD@{1}

但这有一个轻微的危险,如果您犯了一个错误,恢复在分离头上所做的提交可能会有点困难。

结帐actual-branch

Git合并{{commit-hash}}