作業ディレクトリをきれいにする必要がありますしないようにあなたの条件を考えると、私はあなたがさらにいくつかのスクリプトを経由して、作業ツリーまたはインデックスのどちらかをきれいにしたくないということを意味すると仮定します。その場合、現在のローカルリポジトリの範囲内で解決策を見つけることはできません。 Gitはマージ時にこのインデックスを広範囲に使用します。競合がなければ作業ツリーについてはわかりませんが、一般的に、マージは現在チェックアウトされているブランチと密接に結びついています。
しかし、あなたの現在のレポで何かを変更する必要はありません。ただし、レポの複製を作成または作成する必要があります。基本的には、レポをクローンし、クローンでマージして元のレポに戻します。どのように動作するかの簡単な例があります。
最初に、作業するサンプルレポが必要です。次の一連のコマンドで作成されます。現在のブランチにはmaster
、そしてマージする準備が整ったブランチはchange-foo
とchange-bar
という2つのブランチになります。
mkdir background-merge-example
cd background-merge-example
git init
echo 'from master' > foo
echo 'from master' > bar
git add .
git commit -m "add foo and bar in master"
git checkout -b change-foo
echo 'from foo branch' >> foo
git commit -am "update foo in foo branch"
git checkout -b change-bar master
echo 'from bar branch' >> bar
git commit -am "update bar in bar branch"
git checkout master
さて、あなたはmaster
で作業している、とあなたはchange-foo
にchange-bar
をマージしたいしていることを想像してみてください。
$ git log --oneline --graph --all
* c60fd41 update bar in bar branch
| * e007aff update foo in foo branch
|/
* 77484e1 add foo and bar in master
次のシーケンスは、現在のマスターブランチを妨害することなくマージを実行します。マージを行う、それを押して、
# clone with absolute instead of relative path, or the remote in the clone will
# be wrong
git clone file://`realpath .` tmp
cd tmp
# this checkout auto-creates a remote-tracking branch in newer versions of git
# older versions will have to do it manually
git checkout change-foo
# creating a tracking branch for the other remote branch is optional
# it just makes the commit message look nicer
git branch --track change-bar origin/change-bar
git merge change-bar
git push origin change-foo
cd ..
rm -rf tmp
簡単に言えば、サブディレクトリに現在のレポのクローンを作成し、そのディレクトリを入力します:スクリプトにこれをパック、あなたが素敵な「バックグラウンド・マージ」コマンドを持っています元のレポに戻ります。終了後、サブディレクトリが削除されます。大規模なプロジェクトでは、毎回新しくクローンを作成するのではなく、最新の状態に保たれた専用のクローンを作成したい場合があります。マージしてプッシュすると、次のようになります。
$ git log --oneline --graph --all
* 24f1916 Merge branch 'change-bar' into change-foo
|\
| * d7375ac update bar in bar branch
* | fed4757 update foo in foo branch
|/
* 6880cd8 add foo and bar in master
質問がありますか?
http://stackoverflow.com/questions/6548046/merging-to-a-branch-in-git-without-switching-to-it(「git push bspec cspec'」) –
'git push 'のドットはどういう意味ですか? –
また、マージが早送りではないかもしれないことを私の質問で明記しました。これはまだ動作しますか? –