Download Scott Chacon

Transcript
158
CH APT ER 6 N G IT TOOL S
It’s important to note that these commits are listed in the opposite order than you
normally see them using the hkc command. If you run a log, you see something like this:
cephkc))lnappu9bkni]p6!d!oDA=@z/**DA=@
]1b0],`]``a`_]p)beha
/-,-10aql`]pa`NA=@IAbkni]ppejc]j`]``a`^h]ia
b3b/b2`_d]jca`iuj]ia]^ep
Notice the reverse order. The interactive rebase gives you a script that it’s going to run.
It will start at the commit you specify on the command line (DA=@z/) and replay the changes
introduced in each of these commits from top to bottom. It lists the oldest at the top, rather
than the newest, because that’s the first one it will replay.
You need to edit the script so that it stops at the commit you want to edit. To do so, change
the word le_g to the word a`ep for each of the commits you want the script to stop after. For
example, to modify only the third commit message, you change the file to look like this:
a`epb3b/b2`_d]jca`iuj]ia]^ep
le_g/-,-10aql`]pa`NA=@IAbkni]ppejc]j`]``a`^h]ia
le_g]1b0],`]``a`_]p)beha
When you save and exit the editor, Git rewinds you back to the last commit in that list and
drops you on the command line with the following message:
cepna^]oa)eDA=@z/
Opklla`]p304.a,`***ql`]pa`pdacaiola_pkdklabqhhuskng^appan
Ukq_]j]iaj`pda_kiiepjks(sepd
cep_kiiep))]iaj`
Kj_aukq#nao]peobea`sepdukqn_d]jcao(nqj
cepna^]oa))_kjpejqa
These instructions tell you exactly what to do. Type the following:
cep_kiiep))]iaj`
Change the commit message, and exit the editor. Then, run this:
cepna^]oa))_kjpejqa
This command will apply the other two commits automatically, and then you’re done. If
you change le_g to a`ep on more lines, you can repeat these steps for each commit you change
to a`ep. Each time, Git will stop, let you amend the commit, and continue when you’re finished.
Reordering Commits
You can also use interactive rebases to reorder or remove commits entirely. If you want to
remove the ]``a`_]p)beha commit and change the order in which the other two commits are
introduced, you can change the na^]oa script from this: