LoginSignup
0
2

More than 5 years have passed since last update.

Git マージリクエストまでの作業フロー

Last updated at Posted at 2017-01-23

マージリクエストを出す側の作業フローメモ

考え方

  • コミットタイミングは意味の単位が理想だが、ハード障害に備えてバックアップ的な用途でもコミット〜プッシュを行いたい
  • 適当にコミットすると意味の曖昧なコミットが増え、コミットログが見づらくなる
  • コミットは任意のタイミングで行い、マージリクエストを出す前に整理する

作業開始

~/swift/cli (master) % git checkout -b my-topic001   
~/swift/cli (my-topic001) % git log --oneline | head -n1    
874127f add yyy.txt                                            

ファイル追加

~/swift/cli (my-topic001) % vi zzz.txt                                                           
~/swift/cli (my-topic001) % git add zzz.txt                                                      
~/swift/cli (my-topic001) % git commit -m 'add zzz.txt'                                       

メンテ1(ここが意味の曖昧なコミット)

~/swift/cli (my-topic001) % vi zzz.txt                                                           
~/swift/cli (my-topic001) % git add zzz.txt                                                   
~/swift/cli (my-topic001) % git commit -m 'edit zzz.txt'                                      

メンテ2(ここも意味の曖昧なコミット)

~/swift/cli (my-topic001) % vi zzz.txt                                                           
~/swift/cli (my-topic001) % git add zzz.txt                                                   
~/swift/cli (my-topic001) % git commit -m 'edit2 zzz.txt'                                     

現在の状態

~/swift/cli (my-topic001) % git log --oneline | head -n4    
7b31472 edit2 zzz.txt
214c780 edit zzz.txt
9c8ce2c add zzz.txt
874127f add yyy.txt

ここでバックアップ

(将来origin/my-topic001を新規で作るため、ここはmy-topic001-bk)

~/swift/cli (my-topic001) % git push origin my-topic001:my-topic001-bk

その間にmasterが変わった

~/swift/cli (master) % vi from-master.txt                                                        
~/swift/cli (master) % git add from-master.txt                                                   
~/swift/cli (master) % git commit -m 'add from-master.txt' 
~/swift/cli (master) % git push origin master
~/swift/cli (master) % git log --oneline | head -n2
5aa0601 add from-master.txt
874127f add yyy.txt

topicでrebaseして取り込み

mergeでも良いが、全体のコミット履歴を1本の流れにする場合rebase

~/swift/cli (my-topic001) % git pull --rebase origin master 

rebaseしたため、'add zzz.txt'以降のコミットIDが変化した

~/swift/cli (my-topic001) % git log --oneline | head                                             
d7e3d30 edit2 zzz.txt
c9c6004 edit zzz.txt
b60f2e7 add zzz.txt
5aa0601 add from-master.txt
874127f add yyy.txt

そろそろマージリクエストするので、このtopicの変更を整理

~/swift/cli (my-topic001) % git rebase -i HEAD~3

ここではedit、edit2をfixupでaddにまとめた

rebaseによって、addのコミットIDがまた変わる。

~/swift/cli (my-topic001) % git log --oneline | head                                             [0:24:06]
6b9a345 add zzz.txt
5aa0601 add from-master.txt

正しい名前でpushする。BKは削除する。

~/swift/cli (my-topic001) % git push origin my-topic001
 * [new branch]      my-topic001 -> my-topic001
~/swift/cli (my-topic001) % git push --delete origin my-topic001-bk

その他

  • 他の作業者がmy-topic001-bkからブランチを作ってしまうと、コミット履歴が混乱する。
  • my-topic001-bkを作らず、そのままバックアップし、整理後のプッシュで--forceでもよい。
  • いずれにしても、整理前のリモートブランチから、他の作業者がブランチを作らないように調整が必要。
0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2