如何将一个分支复制到另一个分支而不管更改 [英] How to copy one branch to another regardless changes?

查看:522
本文介绍了如何将一个分支复制到另一个分支而不管更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Git比较陌生,我通常使用SVN。
我们有几个分支。因为我一段时间都没有使用过我的分支,所以主分支远远超过了我的分支。如何将主分支复制到我的分支(无论我的更改是本地还是远程)? 解决方案

假设您想<强>删除对本地分支所做的所有更改并从主开始重新开始:

快速方法

  git checkout< your-branch> 
git reset --hard master
git push -f origin< your-branch> #警告危险命令!!!!

长方法可能会更容易理解



转到master分支

  git checkout master 

现在删除您的分支,包括该分支上的所有工作!

  git分支-D  

现在重新创建master上的分支,因为您仍然在master上,您可以这样做: p>

  git checkout -b< your-branch> 

现在将其推送到远程。您需要强制推送到远程,这是危险,因为您正在更改遥控器上的历史记录(已同意,现在只适用于您的分行)。

  git push -f origin< your-branch> 


I'm relatively new to Git; I usually use SVN. We have several branches. Because I have not used my branch for a while, the master branch is far ahead of my branch. How can I copy master branch to my branch regardless my changes (both locally and remotely)?

解决方案

suppose you want to remove all changes to your local branch and start again from master:

THE FAST METHOD

git checkout <your-branch>
git reset --hard master
git push -f origin <your-branch> #WARNING DANGEROUS COMMAND!!!!

THE LONG METHOD BUT MAYBE EASIER TO UNDERSTAND

go to master branch

git checkout master

now delete your branch, including all your work on that branch!

git branch -D <your-branch>

now recreate the branch on master, since you are still on master, you can just do:

git checkout -b <your-branch>

now push this to remote. You need to force pushing to remote, which is dangerous since you are changing your history on the remote (agreed, only for your-branch now)

git push -f origin <your-branch>

这篇关于如何将一个分支复制到另一个分支而不管更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆