[英]Rebasing local Git branch before push to remote
Remotes: origin 遥控器: 原产地
$ git branch
* master
$ git checkout -b "new_feature"
Now I do couple of commits on "new_feature" branch and want to push it to origin after updating it. 现在我在“new_feature”分支上进行了几次提交,并希望在更新后将其推送到原点 。
$ git branch
master
* new _feature
$ git pull --rebase origin new_feature
$ git push origin new_feature
Is this the correct way to update the local branch before pushing to remote? 这是在推送到远程之前更新本地分支的正确方法吗?
You want to use 你想用
git pull --rebase origin master
The arguments to git pull
must be an optional remote, and an optional refspec or reference/branch on that remote : 在将参数git pull
必须是可选的远程, 以及遥控器上的一个可选的Refspec或参考/分支:
git pull [options] [<repository> [<refspec>…]]
new_feature
won't work because it's a local branch, and additionally, it doesn't make sense for the rebase
, because you want to pass a revision to rebase
the branch new_feature
on top of . new_feature
不会起作用,因为它是一个地方分支,另外,它没有任何意义的rebase
,因为你想传递一个修订rebase
分支new_feature
之上 。 If you have new_feature
checked out, then it's understood/implicit that that's the branch you want to rebase
, that's how rebase
normally works. 如果你有new_feature
查出来,那么它的理解/隐含的意思就是你要的分支rebase
,这是怎么rebase
工作正常。
After creating your "new_feature" branch the you will have a state like 创建“new_feature”分支后,您将拥有类似的状态
o <master> <origin/master> <new_feature> most recent commit
|
...
Then, after commiting your changes to your local branch your repository will look like 然后,在将更改提交到本地分支后,您的存储库将如下所示
o <new_feature> your last commit
|
o your first commit
|
o <master> <origin/master> most recent commit
|
...
Doing a 做一个
git pull --rebase origin master
, as Cupcake suggests, you will end with 正如Cupcake建议的那样,你将以此结束
o <new_feature> your last commit
|
o your first commit
|
o <origin/master> something meanwhile commited on remote master
|
o <master> most recent commit
|
...
your changes rebased on top of "origin/master". 您的更改在“origin / master”之上重新定位。 These are not your original commits but commits changed to fit on the "new" "origin/master". 这些不是您的原始提交,但提交已更改为适合“新”“origin / master”。
Doing rebase you can get merge conflicts, because changes made on remote master may conflict with your changes. 执行rebase可以获得合并冲突,因为在远程主服务器上进行的更改可能会与您的更改冲突。
But because "new_feature" is now "on top of" "origin/master" you can do a push to the remote master. 但是因为“new_feature”现在“在”origin / master“之上”,你可以推送到远程主机。
This will also move the tag "origin/master" to the level of "new_feature". 这也将标签“origin / master”移动到“new_feature”的级别。 If you also want to have your local "master" on track, you have then to check it out and do a merge with "origin/master". 如果您还想让您的本地“主人”在轨道上,那么您必须检查它并与“origin / master”合并。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.