Git用分支覆盖master

Arp*_*wal 21 git

我想在更改之后用特定的分支覆盖master,我做的是:

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

git checkout branch_name
Run Code Online (Sandbox Code Playgroud)

第2步:我在代码中做了一些更改,现在我想把这个分支作为master,因为我首先运行命令:

git status
Run Code Online (Sandbox Code Playgroud)

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

现在我的问题是,我需要做什么才能用这个特殊的分支"my_branch"覆盖master?

ara*_*aer 61

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

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

  • 对我来说,`git push origin + dev_branch:master`工作.谢谢! (9认同)
  • 获取:`致命:'远程'似乎不是git存储库` (2认同)
  • 这里的“远程”是指您的遥控器。最有可能是“起源”。 (2认同)
  • 如果您收到“致命:无法强制更新当前分支。”请确保移出“master”分支 (2认同)

use*_*644 32

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

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
Run Code Online (Sandbox Code Playgroud)

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

  • 这对我不起作用。我只是收到“已经更新”消息,而回购中没有任何实际更改。 (2认同)