通过一个命令(或者仅仅是几个)来拉取,重新绑定, [英] Pull, rebase, push, in one command (or just a few)
问题描述
在使用Git时,我经常在 master
中工作时发现以下内容:
#工作工作...
$ git checkout -b temp
$ git commit -a -m'完成更多工作'
$ git checkout master
$ git pull起源大师
#变成大师更新自从我以前的拉
$ git checkout temp
#我不想为简单的bug修正提交合并提交
$ git rebase master
$ git checkout master
$ git merge temp
$ git push origin master
$ git branch -d temp
...我厌倦了这样做。有没有一种方法可以在没有所有结帐的情况下进行跳舞,并且最好不用(手动)创建临时分支? 解决方案
如果你不介意创建一个名为 temp
的分支,你可以在 master
:
git commit -a -m'完成了更多工作'
git fetch origin
git rebase origin / master
...或等同:
git commit -a -m'完成了更多工作'
git pull --rebase origin master
然而,如果您想保留 temp
分支,您仍然可以通过不检出 master
只需做拉
- 您只需要 fetch
然后重新分配你的分支到 origin / master
:
#work work work。 ..
$ git checkout -b temp
$ git commit -a -m'更多工作d一个'
$ git fetch origin
#它看起来像是origin / master被更新了,所以:
$ git rebase origin / master
#然后当你最终想要合并时:
$ git checkout master
$ git merge temp
$ git push origin master
$ git branch -d temp
提示我可以替换: $ git fetch origin
sehe's answer
$ git pull --rebase origin master
...这几乎相当于。不同的是,当你运行 git fetch origin
时,你所有的远程追踪分支 origin
都会被更新,而当你从 origin
拉一个特定的分支时,它们都不是 - 它只是被更新的临时ref FETCH_HEAD
。我个人更喜欢运行一个额外的命令( git fetch origin
),并查看输出中已更改的所有远程分支。
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?
If you don't mind not creating a branch called temp
, you could just do the following all on master
:
git commit -a -m 'more work done'
git fetch origin
git rebase origin/master
... or equivalently:
git commit -a -m 'more work done'
git pull --rebase origin master
If you do want to keep the temp
branch, however, you can still make this a bit shorter by not checking out master
just to do the pull
- you only need to fetch
and then rebase your branch onto origin/master
:
# work work work...
$ git checkout -b temp
$ git commit -a -m 'more work done'
$ git fetch origin
# It looks like origin/master was updated, so:
$ git rebase origin/master
# Then when you finally want to merge:
$ git checkout master
$ git merge temp
$ git push origin master
$ git branch -d temp
sehe's answer reminds me that you could replace:
$ git fetch origin
$ git rebase origin/master
... with:
$ git pull --rebase origin master
... which is nearly equivalent. The difference is that when you run git fetch origin
, all of your remote-tracking branches for origin
will be updated, whereas when you pull a particular branch from origin
, none of them are - it's just the temporary ref FETCH_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.
这篇关于通过一个命令(或者仅仅是几个)来拉取,重新绑定,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!