Git没有我问就合并了吗?为什么? [英] Git merged without me asking? Why?
问题描述
我正在做硕士,完成了我需要做的,然后做了
I was working on master, finished up what I needed to do, then did
git commit -am "message".
我想测试编写一个新功能,所以我做了:
I wanted to test out writing a new feature, so I did:
git branch NewFeature
之后
git checkout NewFeature
然后我对版本控制的文件进行了更改,回到git并做了
I then made changes to version controlled files, came back to git and did
git checkout master
我忘记要做的是将这些更改提交到NewFeature分支.我的错,是的,但是环顾四周,如果没有-f标志,那似乎应该失败了.不幸的是,它只是将我的更改与master合并.自然,我吓坏了,做完了
What I forgot to do was commit those changes to the NewFeature branch. My fault, yes, but looking around on SO it seems like that should have failed without the -f flag. Unfortunately, it just merged my changes with master. Naturally I freaked out and did
git reset --hard head
当我也切换回去时,似乎失去了在NewFeature分支上所做的所有工作!我做错了什么?
It seems like I lost all the work I had done on the NewFeature branch when I switched back as well! What did I do wrong?
推荐答案
这是正常现象.
如果分支之间的更改没有冲突,则git只是移动"目录.结帐时的更改.结帐后,Git应该会向您显示已移动文件的摘要.
If you don't have conflicting changes between branches, git simply "moves" the changes over when you checkout. Git should show you a summary of the moved files after the checkout.
执行 git reset --hard HEAD
将恢复您的更改.
如果您尚未提交更改,但又想在其他分支中进行其他操作,则可以将更改存储起来以备后用.请参阅存储文档.
If you have uncommitted changes but you want to work on other things in a different branch, you can stash your changes for later. See stash docs.
-
git stash
-
git checkout< branch>
- 进行更改并确认
-
git checkout< oldBranch>
-
git stash pop
取消隐藏
git stash
git checkout <branch>
- Make your changes and commit
git checkout <oldBranch>
git stash pop
to un-stash
这篇关于Git没有我问就合并了吗?为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!