Answers:
正在做:
git checkout master
git pull origin
将获取并合并origin/master分支(您可能会说git pull默认为origin)。
尝试git merge origin/master。如果您想确保它只做一个快进,可以说git merge --ff-only origin/master。
merge命令,因此不必重新进行身份验证。
--ff-only非常有用。
origin/master是必需的一部分,或者如果它合理的默认值,但我发现它有用,使快进的别名,所以我想肯定使上游分支是用来代替硬编码它到origin/master:ff = merge --ff-only @{u}(@{u}上游) 。
根据您的情况,git rebase也可以解决问题。由于您没有master所没有的任何更改,因此git会快速前进。如果您使用的是变基工作流程,则可能更可取,因为如果搞砸了,最终不会得到合并提交。
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
git checkout master
git pull
应该做的工作。
每次在不同于master的分支上工作时,都会收到“您的分支在后面”的消息,有人更改了master并进行了git pull。
(branch) $ //hack hack hack, while someone push the changes to origin/master
(branch) $ git pull
现在原点/主基准拉,但你的主人是未合并与它
(branch) $ git checkout master
(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
现在您的主人和原籍/主人已经同步
无需复杂性,只需站在您的分支机构并执行git pull 就可以了
或者, 仅当您不满意第一个命令时,才可以尝试第二次尝试git pull origin master
要变基的当前本地跟踪器分支移动最新的远程状态的顶部局部变化:
$ git fetch && git rebase
更一般而言,要快进并丢弃本地更改(硬重置)*:
$ git fetch && git checkout ${the_branch_name} && git reset --hard origin/${the_branch_name}
以快进和保持局部变化(衍合):
$ git fetch && git checkout ${the_branch_name} && git rebase origin/${the_branch_name}
*-要撤消由无意的硬重置引起的更改,请先执行do git reflog,以相反的顺序显示HEAD的状态,在重置操作之前找到HEAD指向的哈希(通常很明显),然后将分支硬重置为该哈希。
就您而言,要快速前进,请运行:
$ git merge --ff-only origin/master
这使用的--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.
我经常快进,以至于需要别名:
$ git config --global alias.ff 'merge --ff-only @{upstream}'
现在,我可以运行此命令以快速前进:
$ git ff
将分支指针移到HEAD:
git branch -f master
您的分支master已经存在,因此git不允许您覆盖它,除非您使用... -f(此参数代表--force)
或者您可以使用rebase:
git rebase HEAD master
自行承担风险;)
git checkout HEAD从不做任何事情。HEAD已经意味着已签出的提交。