基本问题,但这一直发生在我身上:
- 在工作分支
- 切换到 master
- git merge working-branch
- git push code> cap deploy (转场)
- 做一杯新茶
然后我回来想想其他的东西,然后开始做一些改变......而仍然是主人。
什么是简单的方法:b $ b
冒着风险,在分行 此页面的部分,但刚刚被删除我所有的编辑!?!也许是因为在 git branch dubious-experiment 和 git checkout master git status 在两个分支上都是相同的(不是主人干净)。所以 git reset --hard< SHA1sum> 消除了对这两者的所有更改!?!
git branch dubious-experiment M --- N ----- O ---- P --- Q(master和dubious-experiment) git checkout master #注意下一个命令:确保git status是#clean,你绝对是在master和#dubious-experiment分支的第一个工作是# git reset --hard< SHA1sum of commit N>解决方案
从您的描述中,我假定您没有提交任何改变 - 是否正确?
如果是的话,这是您的答案: 如何防止直接编辑要掌握
您需要在编辑器中设置它,但这可能很困难。在你的提示和你的编辑器中显示你当前的分支会有很大帮助。 如何将更改移动到新分支 new-working-branch ,然后放弃工作分支
git checkout -b新工作分支 git add ... git commit -mmycommit由于您还没有提交任何东西来掌握,所以您无需在主控上更改任何内容。如果您喜欢,现在可以放弃您的工作分支。
如何将更改移至 working-branch git checkout -b temp-branch git add ... git commit -mmycommit git rebase --onto working-branch master git checkout working-branch git reset --hard temp-branch git branch -d temp-branch如果您的更改与master上的任何更改没有冲突,但不在working-branch中,这可能是做了很多简单:
git stash git checkout working-branch git stash pop
Basic question but this happens to me all the time:
- Make changes in a working-branch
- Switch to master
- git merge working-branch
- git push
- cap deploy(to staging)
- make a new cup of tea
then I come back and think of something else and start making some changes...while still on master.
What's an easy way to either:
Took a risk and tried recommendation in the latter part of "Branches" section of this page but that just wiped out ALL my edits!?! perhaps because after git branch dubious-experiment and git checkout master the git status on both branches was identical (not 'clean' on master). So git reset --hard <SHA1sum> wiped out all changes on both!?!
git branch dubious-experiment M---N-----O----P---Q ("master" and "dubious-experiment") git checkout master # Be careful with this next command: make sure "git status" is # clean, you're definitely on "master" and the # "dubious-experiment" branch has the commits you were working # on first... git reset --hard <SHA1sum of commit N>解决方案
From your description, I assume that you did not commit any changes yet – is that correct?
If yes, here’s your answers:
How to prevent direct edits to masterYou would need to set that in your editor, but that will probably be difficult. Displaying your current branch in your prompt and your editor helps a lot.
How to move the changes into a new branch new-working-branch and then discard working-branch git checkout -b new-working-branch git add … git commit -m "mycommit"As you didn’t commit anything to master yet, you don’t need to change anything on master. You can now discard your working-branch if you feel like it.
How to move the changes over to working-branch git checkout -b temp-branch git add … git commit -m "mycommit" git rebase --onto working-branch master git checkout working-branch git reset --hard temp-branch git branch -d temp-branchIf your changes don’t conflict with any changes that are on master, but not in working-branch, this can be done a lot simpler:
git stash git checkout working-branch git stash pop
更多推荐
Git:将更改从主分支移开
发布评论