Git拉错了分支 [英] Git pull into wrong branch
问题描述
我和其他一名开发人员合并,并将我们的工作推向一个称为工具的非主分支。这样,我们并没有影响到其他团队。
#做一些工作
git checkout DPM-93我的主题分支叫做DPM-93,我的git工作流程是这样的。 -93
git commit -m做了一些工作
#追上
git checkout工具
git pull原点工具
# rebase my topic branch
git checkout DPM-93
git rebase toolwork
#合并并推送我的更改
git checkout toolwork
git merge --no -ff DPM-93
git push origin toolwork
大部分工作正常,直到我意外地发出这些git命令
$ g $ check $ g $ git checkout toolwork $ b $ git pull origin master
$ / code>
此时,一些新的东西出现在分支工具中,我不确定如何摆脱删除我的工作空间以及重新克隆回购。
有什么办法可以将它退回到拉之前的状态吗?
git reset --har d ORIG_HEAD
从 git reset
手册页(如果你只是做了拉):
撤销合并或拉取
$ git pull(1)
has没有进行合并提交,所以
自动合并nitfol
CONFLICT(内容):合并nitfol中的冲突
自动合并失败;修复冲突,然后提交结果。
$ git reset --hard(2)
$ git pull。 topic / branch(3)
从41223 ...更新至13134 ...
快进
$ git reset --hard ORIG_HEAD(4)
$ c
$ block
$ ol
尝试从上游更新导致很多冲突;您还没准备好现在花费大量时间进行合并,因此您稍后决定这么做。 pull git reset --hard
这是git reset --hard HEAD
清除索引文件和工作树中的垃圾。
pull或merge总是将当前分支的原始尖端保留在
ORIG_HEAD
,因此难以重置会使索引文件和工作树回到该状态,并将分支的尖端重置为该提交。
请参阅 HEAD
和 ORIG_HEAD
以获得更多信息。
Myself and one other developer had been merging and pushing our work to a non-master branch called toolwork. That way, we didn't impact the rest of the team. My topic branch was called DPM-93 and my git workflow was this.
# do some work
git checkout DPM-93
git commit -m "did some work"
# catch up
git checkout toolwork
git pull origin toolwork
# rebase my topic branch
git checkout DPM-93
git rebase toolwork
# merge and push my changes
git checkout toolwork
git merge --no-ff DPM-93
git push origin toolwork
That was mostly working fine until I accidently issued these git commands
git checkout toolwork
git pull origin master
At that point, a bunch of new stuff showed up in branch toolwork and I'm not sure how to get rid of it short of deleting my workspace and re-cloning from the repo.
Is there any way to back this out to the state before the pull?
git reset --hard ORIG_HEAD
From the git reset
man page (if you just did the pull):
Undo a merge or pull
$ git pull (1)
Auto-merging nitfol
CONFLICT (content): Merge conflict in nitfol
Automatic merge failed; fix conflicts and then commit the result.
$ git reset --hard (2)
$ git pull . topic/branch (3)
Updating from 41223... to 13134...
Fast-forward
$ git reset --hard ORIG_HEAD (4)
- Try to update from the upstream resulted in a lot of conflicts; you were not ready to spend a lot of time merging right now, so you decide to do that later.
- "
pull
" has not made merge commit, so "git reset --hard
" which is a synonym for "git reset --hard HEAD
" clears the mess from the index file and the working tree.- Merge a topic branch into the current branch, which resulted in a fast-forward.
- But you decided that the topic branch is not ready for public consumption yet.
"pull" or "merge" always leaves the original tip of the current branch inORIG_HEAD
, so resetting hard to it brings your index file and the working tree back to that state, and resets the tip of the branch to that commit.
See HEAD
and ORIG_HEAD
for more.
这篇关于Git拉错了分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!