我长时间在分支上开发后切换到了主人.日志显示:
您的分支在167个提交后面是"origin/master",可以快速转发.
我试过了:
git checkout HEAD
Run Code Online (Sandbox Code Playgroud)
它没有效果.这是因为我在master上签出了一个中间提交.
如何让主人留在头上?
rob*_*off 330
试试git merge origin/master.你可以说,如果你想确保它只做一个快进git merge --ff-only origin/master.
Gre*_*ill 235
这样做:
git checkout master
git pull origin
Run Code Online (Sandbox Code Playgroud)
将获取并合并origin/master分支(您可以说git pull原点是默认值).
voi*_*tor 36
在你的情况下,git rebase也可以做到这一点.由于你没有master没有的更改,git只会快进.如果您正在使用rebase工作流,那可能更合适,因为如果您陷入困境,您最终不会得到合并提交.
username@workstation:~/work$ git status
# On branch master
# Your branch is behind 'origin/master' by 1 commit, and can be fast-forwarded.
# (use "git pull" to update your local branch)
#
nothing to commit, working directory clean
username@workstation:~/work$ git rebase
First, rewinding head to replay your work on top of it...
Fast-forwarded master to refs/remotes/origin/master.
# On branch master
nothing to commit, working directory clean
Run Code Online (Sandbox Code Playgroud)
Kub*_*uba 27
git checkout master
git pull
Run Code Online (Sandbox Code Playgroud)
应该做的工作.
每当你在一个不同于主人的分支上工作时,你会得到"你的分支在后面"的消息,有人确实改变了主人并且你git pull.
(branch) $ //hack hack hack, while someone push the changes to origin/master
(branch) $ git pull
Run Code Online (Sandbox Code Playgroud)
现在拉出了原点/主参考,但是你的主机没有与它合并
(branch) $ git checkout master
(master) $
Run Code Online (Sandbox Code Playgroud)
现在master在origin/master之后,可以快速转发
this will pull and merge (so merge also newer commits to origin/master)
(master) $ git pull
this will just merge what you have already pulled
(master) $ git merge origin/master
Run Code Online (Sandbox Code Playgroud)
现在你的主人和原始人/主人是同步的
Sun*_*tel 16
对于想要快进的任何人,如果不检查该分支,他们就不会进入另一个远程分支(包括它自己),您可以这样做:
git fetch origin master:other
Run Code Online (Sandbox Code Playgroud)
如果您不在分支上,这基本上会快进otherto的索引。您可以通过这种方式快进多个分支。origin/masterother
如果您在另一个分支上工作了一段时间,并且想将旧分支从远程更新到它们各自的头:
git fetch origin master:master other:other etc:etc
Run Code Online (Sandbox Code Playgroud)
在您的情况下,要快进,请运行:
$ git merge --ff-only origin/master
Run Code Online (Sandbox Code Playgroud)
这使用 的--ff-only选项git merge,因为问题特别要求“快进”。
以下是git-merge(1)显示更多快进选项的摘录:
--ff, --no-ff, --ff-only
Specifies how a merge is handled when the merged-in history is already a descendant of the current history. --ff is the default unless merging an annotated
(and possibly signed) tag that is not stored in its natural place in the refs/tags/ hierarchy, in which case --no-ff is assumed.
With --ff, when possible resolve the merge as a fast-forward (only update the branch pointer to match the merged branch; do not create a merge commit). When
not possible (when the merged-in history is not a descendant of the current history), create a merge commit.
With --no-ff, create a merge commit in all cases, even when the merge could instead be resolved as a fast-forward.
With --ff-only, resolve the merge as a fast-forward when possible. When not possible, refuse to merge and exit with a non-zero status.
Run Code Online (Sandbox Code Playgroud)
我经常快进,以至于它需要一个别名:
$ git config --global alias.ff 'merge --ff-only @{upstream}'
Run Code Online (Sandbox Code Playgroud)
现在我可以运行它来快进:
$ git ff
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
240888 次 |
| 最近记录: |