通过一个命令(或几个命令)拉取、变基、推送

发布于 2024-12-06 13:03:02 字数 501 浏览 0 评论 0原文

使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

吃素的狼 2024-12-13 13:03:02

如果您不介意不创建名为 temp 的分支,则可以在 master 上执行以下操作:

git commit -a -m 'more work done'
git fetch origin
git rebase origin/master

... 或等效的操作:

git commit -a -m 'more work done'
git pull --rebase origin master

如果您确实想保留temp 分支,但是,您仍然可以通过不签出 master 只是为了执行 pull 来缩短这个时间 - 您只需要 < code>fetch 然后将你的分支重新定位到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 的回答提醒我,您可以将:

$ git fetch origin
$ git rebase origin/master

...替换为:

$ git pull --rebase origin master

...,这几乎等效。不同之处在于,当您运行 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 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.

ζ澈沫 2024-12-13 13:03:02

您至少可以优化变基: git pull --rebase

我不太确定你喜欢什么,但我喜欢我的工作流程有点像这样:

git checkout -b temp
git commit -a -m 'more work done'
git pull --rebase origin master

这样我就可以将注意力集中在手头的分支上。

然后后来我就这样做了

git checkout master
git pull origin master
git merge temp

等等。

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:

git checkout -b temp
git commit -a -m 'more work done'
git pull --rebase origin master

That way I keep my focus on the branch at hand.

Then later, I do

git checkout master
git pull origin master
git merge temp

etc.

回眸一笑 2024-12-13 13:03:02
git pull --rebase --autostash origin staging && git push origin staging; 
git pull --rebase --autostash origin staging && git push origin staging; 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文