简体   繁体   English

git分支实验

[英]git branching experimental

Well I've been working for a project. 好吧,我一直在为一个项目工作。 today I was experimenting with windows specific wchar and I needed to do change a lot of code since morning and I ended up with an ugly mess. 今天我正在试验Windows特定的wchar ,我需要在早上改变很多代码,最后我得到了一个丑陋的混乱。 That I can clear out latter but right now I need to do some mainstream works on last working commit. 我可以清除后者,但现在我需要在最后一次工作提交上做一些主流工作。 But I don't want to loose this work. 但我不想放松这项工作。 So how can I keep this work in some branch for future and revert my workspace back to last commit ? 那么如何将这项工作保留在某个分支中以备将来使用,并将我的工作区恢复到上一次提交?

You can create a new branch and commit your changes to it: 您可以创建一个新分支并将更改提交给它:

git checkout -b topic/ugly-mess
git commit -a -m 'Checkpointing mess.'

Then go back to your mainstream branch which has the last working commit: 然后回到你的最后一个工作提交的主流分支:

git checkout master

If you want your to publish your "local mess" upstream, push the branch: 如果您希望在上游发布“本地混乱”,请推动分支:

git push origin topic/ugly-mess

Simply create a new branch 只需创建一个新分支

git branch -b wchar_migration

and commit your changes into it 并将您的更改提交到其中

git commit -am "wchar ..."

then go back to your work 然后回到你的工作

git checkout master

If later you want to include the modification you made on master, simply rebase on it. 如果以后要包含您在master上进行的修改,只需在其上进行rebase。

git co wchar_migration
git rebase master

You probably don't even need a branch. 你可能甚至不需要分支。 If you use git stash , git stashes (stores) the current 'dirty' workspace and returns you to a clean workspace. 如果你使用git stash ,git stashes(存储)当前的“脏”工作区并返回一个干净的工作区。 You can apply the stashed changes later if you want. 如果需要,您可以稍后apply隐藏的更改。

So long as you haven't committed any of this work, you can always git stash your experiment. 只要你没有投入任何这项工作,你就可以随时git stash你的实验。

But you've described this as experimental so another option, and probably the better one, is to keep this work in it's own branch, eg git checkout -b wcharExperiment , commit the work into this new branch, then checkout your main branch. 但是你已经把它描述为实验性的,所以另一种选择,也许是更好的选择,就是让它在自己的分支中工作,例如git checkout -b wcharExperiment ,将工作提交到这个新的分支,然后检查你的主分支。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM