如何将我当前的更改提交给git中的其他分支
这个问题在这里已经有了答案:
  其他的答案建议检查另一个分支,然后对其进行承诺,只有在结账可以进行本地修改的情况下才有效。  如果没有,你在git stash最常见的用例: 
git stash
git checkout other-branch
git stash pop
  第一个stash隐藏了您的更改(基本上是进行临时提交),随后的stash pop重新应用它们。  这让git可以使用它的合并功能。 
如果当你试图弹出藏匿处,你会遇到合并冲突......接下来的步骤取决于这些冲突是什么。 如果所有隐藏的变化确实属于另一个分支,那么您只需要对它们进行排序 - 这是对错误分支进行更改的结果。
另一方面,如果你真的搞砸了,而且你的工作树有两个分支的变化混合,并且冲突只是你想要在原始分支上提交的冲突,那么你可以保存一些工作。 像往常一样,有很多方法可以做到这一点。 这里有一个,从你弹出并看到冲突之后开始:
# Unstage everything (warning: this leaves files with conflicts in your tree)
git reset
# Add the things you *do* want to commit here
git add -p     # or maybe git add -i
git commit
# The stash still exists; pop only throws it away if it applied cleanly
git checkout original-branch
git stash pop
# Add the changes meant for this branch
git add -p 
git commit
# And throw away the rest
git reset --hard
或者,如果您在这种情况发生之前意识到,只需提交属于当前分支的内容即可。 你总是可以回来修改那个提交:
git add -p
git commit
git stash
git checkout other-branch
git stash pop
  当然,请记住这一切都需要做一些工作,下次避免它,也许可以通过在您的bashrc $(__git_ps1)添加到PS1中,将您的当前分支名称放入提示中。  (例如参见Bash文档中的Git。) 
你可以创建一个新的分支并切换到它。 然后提交您的更改:
git branch dirty
git checkout dirty
// And your commit follows ...
  另外,你也可以签出一个现有的分支(只是git checkout <name> )。  但是,只有在没有冲突的情况下(所有编辑文件的基数与当前分支中的基数相同)。  否则,你会收到一条消息。 
git checkout my_other_branch git add my_file my_other_file git commit -m 并提供您的提交信息。
链接地址: http://www.djcxy.com/p/22453.html上一篇: How to commit my current changes to a different branch in git
