1

ここスタックや他のフォーラムでさまざまな解決策を検索して試してみましたが、この問題を解決できないようです。

Git: ブランチは X コミット分先行しています。git pull の実行に役立たない

最新のように見え、プッシュプル (ファイルなし) で修正されるのに、git が 40 コミット先だと言うのはなぜですか?

オリジン マスターを *pull* する必要があるときに、「あなたのブランチはオリジン/マスターより 857 コミット進んでいます」と表示されるのはなぜですか

全体的な問題は、サイトのチェックアウトをプルしてから、構成 (データベース、API の場所など) にいくつかのローカル変更を加える必要があり、先に進んでローカル変更をコミットするたびに隠して再適用する必要がないようにしたことです。これらのファイル。「ローカル構成コミット」として、これらすべてを1つのローカルコミットで行いました。この時点で git status は 1 進んでいます。

root@web1 web]# git status
 On branch master
 Your branch is ahead of 'origin/master' by 1 commits.

ただし、この 1 か月間、開発と修正を行ってきました。私たちは皆、別々のブランチから離れて開発ブランチにマージし、そこから master などに取り組んでいます。準備が整ったら、本番環境に戻り、「git pull」を使用して変更をプルダウンします。これはうまく機能しているように見えますが、ステータスが変わっていることに今日気づきました。

root@web1 web]# git status
On branch master
Your branch is ahead of 'origin/master' by 31 commits.

origin/master に対する git ログを見ると、ローカル コミットとしてマージが行われているように見えますか?

小さなログ スニペット:

[root@web1 web]# git log origin/master..HEAD 
commit 336743eb411804487ad2f8a2e31701b094fb03f0
Merge: 58c8230 3478924
Author: root <root@web1.(none)>
Date:   Fri Feb 1 15:32:35 2013 -0500

    Merge branch 'master' of http://gitrepo.com/Site

commit 58c82303c523a3c9217dd677ba23582e168007cc
Merge: 6c9de32 0e1c327
Author: root <root@web1.(none)>
Date:   Fri Feb 1 15:04:58 2013 -0500

    Merge branch 'master' of http://gitrepo.com/Site

commit 6c9de32c2fed77e442e73389aa8041f067a23cc4
Merge: ff586b4 52a7ea9
Author: root <root@web1.(none)>
Date:   Fri Feb 1 14:38:08 2013 -0500

    Merge branch 'master' of http://gitrepo.com/Site

私のレポは適切に「早送り」されていて、プルするたびに1コミット先に座っているのではないかと思います。origin/master に対して diff を実行すると、(一見) 構成のみに多くの変更が加えられていないことがわかります。これは、元の構成変更とローカル コミットによるものです。

[root@web1 web]# git diff origin/master..HEAD --name-only
application/config/api.php
application/config/config.php
application/config/database.php

上記のさまざまなリンクを試し、フェッチやプルなどを試しましたが、役に立ちませんでした。ローカル リポジトリを適切に早送りして、作成したローカル コミットが 1 つだけ表示されるようにする方法はありますか? これらの変更をマスターに正確にプッシュすることはできません。これにより、これらの変更が他のインストールに引き下げられる可能性があります。そして、この問題を解決した後、展開し、いくつかの構成を変更し、継続的に更新できる最善の方法は何だと思います。私の理解では、スタッシュは機能しますが、これは本質的に変更を適切な場所に移動し、プルしてから再適用できますが、特にマージを整理する必要がある場合は、この小さなステップのダウンタイムを許容できません競合します。

または、これらのファイルを何らかの方法でコミットから取り出して、プッシュしてすべてをソートできるようにする方法はありますか?

4

1 に答える 1

1

You can't do a fast-forward if you have a local commit that isn't in origin/master, it has to be a merge instead. A fast-forward is done when you are behind the remote, with no local changes. Since you have a local change, you can't fast-forward.

Maybe what you want is to rebase, which will temporarily undo your local commit, fast-forward to the tip of the remote branch, then reapply your local commit as the last commit.

git rebase origin/master

Or, if it's set as the default upstream, and you're not using an old version of Git, just

git rebase

Some people always use rebasing to pull from a remote, which is needed if the remote is configured to reject merge commits, but you should understand what rebasing does before using it willy-nilly, see http://git-scm.com/book/en/Git-Branching-Rebasing and http://darwinweb.net/articles/the-case-for-git-rebase

于 2013-02-08T09:32:40.383 に答える