git 如何使用git覆盖具有不同本地分支的远程分支
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/39389380/
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
How to overwrite remote branch with different local branch with git
提问by Manuel Schiller
I have a remote branch that is the basis for a pullrequest.
我有一个远程分支,它是 pullrequest 的基础。
I mainly worked on a different branch, however that should now replace the old branch.
我主要在一个不同的分支上工作,但是现在应该取代旧分支。
I tried to do a git push remote oldBranch -f
but that only pushes my latest local oldBranch
to the git server instead of the current branch - no matter which branch i am currently on.
我试图做一个,git push remote oldBranch -f
但这只会将我最新的本地推oldBranch
送到 git 服务器而不是当前分支 - 无论我目前在哪个分支上。
How can I replace the remote branch with my local branch?
如何用我的本地分支替换远程分支?
EDIT: If anybody else is interested, this is how i got this to work:
编辑:如果其他人有兴趣,这就是我让它工作的方式:
git checkout oldBranch
git branch -m 'oldBranchToBeReplaced'
git checkout newBranch
git branch -m oldBranch
git push myrepo oldBranch -f
回答by Martin Nyolt
You can use the local-name:remote-name
syntax for git push:
您可以使用local-name:remote-name
git push的语法:
git push origin newBranch:oldBranch
This pushes newBranch
, but using the name oldBranch
on origin.
这会推动newBranch
,但使用oldBranch
原点上的名称。
Because oldBranch
probably already exists, you have to force it:
因为oldBranch
可能已经存在,所以你必须强制它:
git push origin +newBranch:oldBranch
(I prefer the +
instead of -f
, but -f
will work, too)
(我更喜欢+
而不是-f
,但-f
也可以工作)
To delete a branch on the remote side, push an "empty branch" like so:
要删除远程端的分支,请像这样推送“空分支”:
git push origin :deleteMe
回答by Tschallacka
From: https://deltacloud.apache.org/send-pull-request.html
来自:https: //deltacloud.apache.org/send-pull-request.html
$ git checkout -b my branch
Coding your changes
$ git commit -m "Commit message"
Pushing your work
Update the original repo This will avoid possible merge conflicts and problems with applying your patches.
推动你的工作
更新原始 repo 这将避免应用补丁时可能出现的合并冲突和问题。
$ git checkout master
$ git pull
Push to your fork.
推到你的叉子上。
$ git checkout my_work_topic
$ git rebase -i master (Tip: You can rename/squash commits at this point)
$ git push origin my_work_topic
Issue the Pull request
发出拉取请求
Navigate to your forked Github repository For example:https://github.com/yourusername/deltacloud-core.git click the Pull Request tab (Tip: You can use hub to automate this step) For more details on using pull requests see: The Official GitHub Help For Using Pull Request
导航到分叉的 Github 存储库 例如:https: //github.com/yourusername/deltacloud-core.git 单击 Pull Request 选项卡(提示:您可以使用 hub 自动执行此步骤)有关使用 pull requests 的更多详细信息,请参阅:使用 Pull Request的官方 GitHub 帮助