Git 用分支覆盖 master

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30105210/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 03:11:31  来源:igfitidea点击:

Git Overwrite master with branch

git

提问by Arpit Aggarwal

I want to overrite master with a particular branch after making changes to it, what I done to do it is:

我想在对其进行更改后使用特定分支覆盖 master,我所做的是:

Step 1: Checkout brranch from Git, using command :

第 1 步:从 Git 结帐分支,使用命令:

git checkout branch_name

Step 2: I done some changes in code, now I want to make this branch as master, for that I first run the command:

第 2 步:我对代码进行了一些更改,现在我想将此分支设为 master,为此我首先运行以下命令:

git status

Above command list me all the modified files.

上面的命令列出了所有修改过的文件。

Now my question, what all I need to do overrite master with this particular branch "my_branch"?

现在我的问题是,我需要做什么来覆盖这个特定分支“my_branch”的master?

回答by aragaer

git branch -f master dev_branchwill rewrite local master branch.

git branch -f master dev_branch将重写本地主分支。

git push remote +dev_branch:masterwill rewrite remote branch.

git push remote +dev_branch:master将重写远程分支。

回答by user2350644

To completely replace the masterbranch with the contents of any other feature_branchyou can also use:

要使用master任何其他内容完全替换分支,feature_branch您还可以使用:

git checkout feature_branch
git merge -s ours --no-commit master
git commit      # Add a message regarding the replacement that you just did
git checkout master
git merge feature_branch

See: http://git.tutorialhorizon.com/2014/10/05/replace-the-master-branch-with-another-branch-in-git/

见:http: //git.tutorialhorizo​​n.com/2014/10/05/replace-the-master-branch-with-another-branch-in-git/