私は長い間ブランチで開発した後、マスターに切り替えました。ログは示しています:
あなたのブランチは167コミットで 'origin / master'の後ろにあり、早送りすることができます。
私は試した:
git checkout HEAD
影響はありません。これは、マスターで中間コミットをチェックアウトしているためです。
マスターを頭に留める方法は?
私は長い間ブランチで開発した後、マスターに切り替えました。ログは示しています:
あなたのブランチは167コミットで 'origin / master'の後ろにあり、早送りすることができます。
私は試した:
git checkout HEAD
影響はありません。これは、マスターで中間コミットをチェックアウトしているためです。
マスターを頭に留める方法は?
回答:
実行:
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
は、トリックも行います。マスターが持っていない変更がないので、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を実行するだけ です
または、 最初のコマンドで運が悪かった場合にのみ、2番目に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}
*-意図しないハードリセットによって引き起こされた変更を元に戻すに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
)
または、リベースを使用できます。
git rebase HEAD master
あなた自身の責任でそれをしてください;)
git checkout HEAD
何もしません。HEAD
既にチェックアウトされたコミットを意味します。