Git:重置其他分支到当前没有结帐
我正在为我的Git工作stream写一些脚本。
我需要将其他(现有)分支重置为当前分支,而无需结帐。
之前:
CurrentBranch: commit A OtherBranch: commit B 后:
  CurrentBranch: commit A OtherBranch: commit A 
等价的
  $ git checkout otherbranch $ git reset --soft currentbranch $ git checkout currentbranch 
(注 – 软件:我不想影响工作树。)
这可能吗?
 您描述的工作stream程并不相同:当您执行reset --hard时 – 您reset --hard失去工作树中的所有更改(您可能希望将其reset --soft )。 
你需要的是
 git update-ref refs/heads/OtherBranch refs/heads/CurrentBranch 
 通过运行设置otherbranch指向与currentbranch相同的提交 
 git branch -f otherbranch currentbranch 
  -f (强制)选项告诉git branch 是的,我的意思是覆盖任何现有otherbranch引用与新的 。 
从文档 :
-F
– 力重置为如果已经存在。 没有-f git分支拒绝改变现有的分支。
您可以随时与这个命令同步您的分支
 $ git push . CurrentBranch:OtherBranch -f 
也没有-f它replace这组命令
 $ git checkout OtherBranch $ git merge CurrentBranch $ git checkout CurrentBranch 
当你不需要在CurrentBranch中提交所有的文件,这样你就不能切换到另一个分支。