25

私は Git から始めているので、このタスクは非常に単純なので、この質問は今日最も新しい質問になる可能性があると感じていますが、ひどい頭痛の種になっています..

私は2つのローカルブランチを持っています:

  • 主人
  • ローカル/生産

そして2つのリモコン:

  • 主人
  • 製造

ローカルの変更を本番環境に渡す必要があります。したがって、私のワークフローは次のとおりです。

git checkout local/production
git merge master
git commit
git push

git merge: 正常に動作しているようです。すべての違いが検出されました。

git コミット:

ブランチ ローカル/プロダクション

あなたのブランチは「オリジン/プロダクション」よりも 2 コミット進んでいます。

コミットするものは何もありません (作業ディレクトリはクリーンです)

そしてgit push:

すべてが最新

以上で、変更をリモート リポジトリにプッシュできませんでした。

4

1 に答える 1

24

根本的な原因:説明を短くするために、あなたlocal/productionが追跡していないように見えますorigin/production。で確認できますgit branch -avv

Aboutgit pushgit push :引数を指定しないと、ローカルの追跡ブランチで更新されたすべてのリモート ブランチが更新されることに注意してください (git-push(1)マニュアル ページから):

git push ...  [<repository> [<refspec>...]]

The special refspec : (or +: to allow non-fast-forward updates) directs git to
push "matching" branches: for every branch that exists on the local side, the
remote side is updated if a branch of the same name already exists on the remote
side. This is the default operation mode if no explicit refspec is found (that is
neither on the command line nor in any Push line of the corresponding remotes
file---see below).

ローカル ブランチでどのような変更が行われたかを忘れると、simple の結果がgit push予期しないものになることがあるため、個人的にはプッシュするブランチを明示的に指定するのが好きです。あなたの場合、これがあなたがやりたいことのようです:

git push origin local/production:production

local/productionを追跡したい場合は、オプションを使用しorigin/productionlocal/production追跡ブランチを作成できます。origin/production-u

git push -u origin local/production:production

(一度だけ必要です)。次に、原点から にプルできますlocal/production

エグゼクティブ サマリー:ブランチの追跡の概念と の固有のセマンティクスを理解する必要がありますgit push

PSここでのブランチ名の選択について疑問に思っていますlocal/production。だけではないのはなぜproductionですか?あなたはすでにproduction追跡origin/productionを行っており、おそらくlocal/productionローカル開発に使用していると思われます。この場合、合理的なワークフローは次のようになります。

  1. git pull origin production:production変更をあなたに引っ張るproduction
  2. に新しいコミットがある場合production、つまり遅れている場合は、 on をlocal/productionリベースする(または on をマージする)local/productionproductionproductionlocal/production
  3. 変更をプッシュしたい瞬間、mergeまたはcherry-pickコミットして変更productionをプッシュしたい瞬間git push origin production:production
于 2012-11-28T04:56:56.640 に答える