通过一个命令(或几个命令)拉取、变基、推送
使用 Git 时,我经常发现自己在 master
中执行以下操作:
# work work work...
$ git checkout -b temp
$ git commit -a -m 'more work done'
$ git checkout master
$ git pull origin master
# turns out master was updated since my previous pull
$ git checkout temp
# I don't want a merge commit for a simple bugfix
$ git rebase master
$ git checkout master
$ git merge temp
$ git push origin master
$ git branch -d temp
...并且我厌倦了这样做。有没有一种方法可以在不进行所有结账的情况下进行这种舞蹈,并且最好不(手动)创建临时分支?
When using Git, I often find myself doing the following when working in master
:
# work work work...
$ git checkout -b temp
$ git commit -a -m 'more work done'
$ git checkout master
$ git pull origin master
# turns out master was updated since my previous pull
$ git checkout temp
# I don't want a merge commit for a simple bugfix
$ git rebase master
$ git checkout master
$ git merge temp
$ git push origin master
$ git branch -d temp
... and I get tired of doing this. Is there a way to do this dance without all of the checkouts, and preferably without (manually) creating the temporary branch?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您不介意不创建名为
temp
的分支,则可以在master
上执行以下操作:... 或等效的操作:
如果您确实想保留
temp
分支,但是,您仍然可以通过不签出master
只是为了执行pull
来缩短这个时间 - 您只需要 < code>fetch 然后将你的分支重新定位到origin/master
:sehe 的回答提醒我,您可以将:
...替换为:
...,这几乎等效。不同之处在于,当您运行
git fetch origin
时,origin
的所有远程跟踪分支都将更新,而当您从origin 拉取特定分支时
,它们都不是 - 它只是更新了临时引用FETCH_HEAD
。我个人更喜欢运行一个额外的命令(git fetch origin
),并查看输出中已更改的所有远程分支。If you don't mind not creating a branch called
temp
, you could just do the following all onmaster
:... or equivalently:
If you do want to keep the
temp
branch, however, you can still make this a bit shorter by not checking outmaster
just to do thepull
- you only need tofetch
and then rebase your branch ontoorigin/master
:sehe's answer reminds me that you could replace:
... with:
... which is nearly equivalent. The difference is that when you run
git fetch origin
, all of your remote-tracking branches fororigin
will be updated, whereas when you pull a particular branch fromorigin
, none of them are - it's just the temporary refFETCH_HEAD
that is updated. I personally prefer running one extra command (git fetch origin
), and seeing all the remote branches that have changed in the output.您至少可以优化变基:
git pull --rebase
我不太确定你喜欢什么,但我喜欢我的工作流程有点像这样:
这样我就可以将注意力集中在手头的分支上。
然后后来我就这样做了
等等。
You can at least optimize the rebasing:
git pull --rebase
I'm not exactly sure how you like things, but I like my workflow sort of like this:
That way I keep my focus on the branch at hand.
Then later, I do
etc.