简体   繁体   English

将未提交的更改提交到另一个分支

[英]Committing uncommited changes to another branch

I'm using sourcetree and only have master branch cloned locally. 我正在使用sourcetree,并且只在本地克隆了master分支。 So I have been doing all my changes on master branch, and finally I have a lot of uncommited changes here on my local machine. 因此,我一直在master分支上进行所有更改,最后在本地计算机上进行了许多未提交的更改。

But right now I decided not to push them to master branch, but rather to develop branch - pretty old branch in my project. 但是现在我决定不将其推入主分支,而是开发分支-我项目中的老分支。 It exists on the origin, but not locally. 它存在于原点,但不存在于本地。

How can I first merge master to develop, so that they're the same, and then commit and push my changes to develop branch, leaving master untouched? 我如何首先合并master进行开发,使它们相同,然后提交并推送更改以进行开发分支,而又不影响master?

I've been thinking about: 我一直在思考:

git checkout origin/develop;
git merge master;

Ok, that would solve the first problem I think, but then my local changes would not be seen - source tree treats them as master changes I believe. 好的,那可以解决我认为的第一个问题,但是然后看不到我的本地更改-源树将它们视为我相信的主要更改。

I am asking for this because I don't want to mess up anything in this project. 我要求这样做是因为我不想弄乱该项目中的任何内容。

So - any suggestions? 所以-有什么建议吗?

Before git checkout and git merge , run git checkoutgit merge之前运行

git stash

to save your uncommitted changes to the Git stash and remove them from your working tree. 将您尚未提交的更改保存到Git存储中,并将其从工作树中删除。 Then, after you've merged, run 然后,合并后运行

git stash apply
git stash drop

to apply those changes you've stashed to your working tree (now on the develop branch) and remove the changes from the stash. 将已存储的更改应用于工作树(现在位于develop分支),并从存储中删除更改。 You could instead run git stash pop , which combines apply and drop , but that has some tricky behavior (when hitting conflicts and such) that makes it better to usually just run apply and drop separately. 您可以改为运行git stash pop ,它结合了applydrop ,但是它具有一些棘手的行为(当遇到冲突等时),使通常只单独运行applydrop更好。

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

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