add
リポジトリにcommit
保存したいすべてのファイルを別のコミットで一度に。
最初のコミットは、追跡したいファイル (つまり、テキスト ファイル) である必要があります。
追跡したいファイルを変更するたびに、通常と同じように新しいコミットを作成します。
一度保存したいファイルを変更するたびに、新しいコミットを作成し、rebase
/fixup
バイナリを追加したコミットにコミットします。
これが実際のアイデアです:
$ ls
banana.pdf bar.bin foo.txt mew.ppt
$ git status -s
?? banana.pdf
?? bar.bin
?? foo.txt
?? mew.ppt
ファイルを追加 - 最初に追跡するファイル、次にすべてのバイナリ
$ git add foo.txt
$ git commit -m "foo text file"
$ git tag "root" HEAD # easy access to the first commit
$ git add banana.pdf bar.bin mew.ppt
$ git commit -m "binaries"
変更してコミットする
$ echo "ohai, I'm a change :D" >> foo.txt
$ git add foo.txt
$ git commit -m "foo changed"
$ echo "ohai, I'm a banana" | hexdump >> banana.pdf
$ git add banana.pdf
$ git commit -m "fixup! binaries"
私たちが持っているものを見てみましょう
$ git log --oneline
42c09bd fixup! binaries # this will be merge with
a9b1853 foo changed
8899046 binaries # this - same commit message!
7c8ae05 foo text file # this is also the 'root' tag
コミットをリベースして、バイナリのコミットを修正します
$ git rebase --autosquash -i root # everything will be ready for us
pick 8899046 binaries
fixup 42c09bd fixup! binaries # notice this :)
pick a9b1853 foo changed
:wq # vim save and quit
$ git log --oneline # lets look at what we end up with
41e1f09 foo changed
50adb90 binaries
7c8ae05 foo text file
「追跡されていない」ファイルの新しいコミットを次のようにマークすることは非常に重要です。
git commit -m "fixup! <same message as the commit to merge with>"
私たちの場合、「banana.pdf」を追加したコミットの元のメッセージはbinaries
、バイナリのいずれかを変更したコミットのコミット メッセージであるべきですfixup! binaries
(例のように)
コミットにそのような名前を付け--autosquash
ないと役に立ちません。変更したいコミットの行を、マージしたいコミットの下に手動で移動し、「pick」を「fixup」に置き換える必要があります。たとえば(出発したところから続けて):
$ echo "ohai, more changes" >> bar.bin
$ git add bar.bin
$ git commit -m "changed bar"
$ git log --oneline
bd36eb9 changed bar
41e1f09 foo changed
50adb90 binaries
7c8ae05 foo text file
$ git rebase -i root
pick 50adb90 binaries # you want this to merge with
pick 41e1f09 foo changed
pick bd36eb9 changed bar # this
に変更します
pick 50adb90 binaries
fixup bd36eb9 changed bar # under the line to be merged with and with 'fixup' instead of 'pick'
pick 41e1f09 foo changed
:wq # save and quit
$ git log --oneline # what we end up with
9f94cbe foo changed
886eebd binaries
7c8ae05 foo text file
終わり :)
さらに先に進みたい場合は、git hookでこれを自動化できます。見る
$ git help githooks
フックはpre-commit
いくつかのトリックであなたのために仕事をします