很簡單,只需要按照以下兩個步驟即可。
1. git rebase -i
git rebase -i的用意就是讓人調整尚未push的commits的順序,例如可以看到
pick 5fce956 BUG_FIX: 10001 pick ebe4b15 BUG_FIX: 10002 pick 719413f BUG_FIX: 10003
此時的git log如下:
commit 719413f85bb7e985fd6cf457eb45001b0262d3b6 Author: Ryan Chou <ryanchou@realtek.com> Date: Tue Aug 12 12:15:47 2014 +0800 BUG_FIX: 10003 commit ebe4b15ba285a8b46a5464a8a1e29aac0e141308 Author: Ryan Chou <ryanchou@realtek.com> Date: Mon Aug 11 19:49:54 2014 +0800 BUG_FIX: 10002 commit 5fce9565ca07a483c35032fa06b1b7e92535b4bb Author: Ryan Chou <ryanchou@realtek.com> Date: Tue Jul 29 11:40:21 2014 +0800 BUG_FIX: 10001
我們稍微調整一下,將順序換一下,變成
pick ebe4b15 BUG_FIX: 10002 pick 719413f BUG_FIX: 10003 pick 5fce956 BUG_FIX: 10001
此時,git log就會便成
commit 372647d7574625733ed8c362b000dd12e559defa Author: Ryan Chou <ryanchou@realtek.com> Date: Mon Aug 11 19:49:54 2014 +0800 BUG_FIX: 10001 commit c16c17750d4c821bbd34d0808c84fe20ed439a06 Author: Ryan Chou <ryanchou@realtek.com> Date: Tue Jul 29 11:40:21 2014 +0800 BUG_FIX: 10003 commit 75cd3e85a56dca2e2d76ef960e498cf25f084ca2 Author: Ryan Chou <ryanchou@realtek.com> Date: Tue Aug 12 12:15:47 2014 +0800 BUG_FIX: 10002
值得注意的是,除了順序換了以外,每個commit的SHA也都跟著換了
2. git push <remote-url> <commit SHA>:<remote-branch-name>
為什麼需要調整commit的順序呢?主要是為了只將一些特定的commit push到remote端
一般push的時候都是
git push <remote-url> HEAD:<remotebranchname>
這時候可以改成
git push <remote-url> <commit SHA>:<remotebranchname>
如此,就只會將<commit SHA>以前的所有改動都放上remoete囉。
沒有留言:
張貼留言