如何处理独立头脑中的犯下行为

使用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 (wich does complete because there was some error due to the fact that i'm no more on master)

因为git对我说,当我处于独立的头部状态时,我仍然可以提交,所以我这样做了。 但现在我想合并我分离的头分支到我的本地主分支,然后将我的更改推送到origin / master。

所以我的问题是我怎么能合并主分支与我的实际状态(分离头)


创建一个分支,然后切换到主并合并它:

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

你可以做这样的事情。

# 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 temproary branch
git branch -d tmp

更简单的是

git checkout master
git merge HEAD@{1}

但是这具有轻微的危险,如果您犯了错误,可能会更难以恢复在分离头上做出的承诺。


你可以做git merge <commit-number>或者git cherry-pick <commit> <commit> ...

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

git branch brand-name

或者只是一个标签:

git tag tag-name
链接地址: http://www.djcxy.com/p/23515.html

上一篇: What to do with commit made in a detached head

下一篇: How to list files ignored with 'skip