abcde, where d is the desired commit, modifying 3 lines.
There is a need to become so: dabce, there are no conflicts associated with changes.
The main thing - how to do it?
- You need a cherry-pick or interactive rebase . An entire chapter in the book ( git-scm.com/book/en/Git-Tools-Rewriting-History ) is devoted to this, but I have not read it, so I will not say anything more precisely. - etki
1 answer
You need git rebase -i HEAD~5 . This command will launch an interactive reabse last 5 commits, during which you can, among other things, change their order. After running this command, a text editor will appear (if you didn’t set up the default editor, vim will open), where each commit will have a line of format
action hash comment In your case, you need to swap lines. In vim, this is done as follows: the cursor hovers over a line, Shift+D , the cursor is moved under the line where you want to insert, Shift+P If something is inserted incorrectly, press i (this will take us to the usual editing mode) and correct it, then press Esc . Then you need to save and exit. To do this, type :wq wq and press Enter . If you change your mind or mess with editing, type :q! and exit without saving. After that, git swaps commits in the order in which they were listed in the edited file.
In general, an interactive rebase can do a lot of interesting things. In particular, you can rename a commit, delete it, merge several commits into one. Read the documentation and you will be happy.