How can I combine two git commands

I made a series of commits, and now I see that I would like 2 commits to be merged. Not the last two, but a little further.

My journal:

commit 326f35d83963660893d065e480f231b76f052dd2 Author: Peter Smit < peter@something.eu > Date: Thu Dec 16 11:13:47 2010 +0200 Small editing in ASR chapter commit 652b4c27a5fcb2125ed82aea31421fca4e8eee47 Author: Peter Smit < peter@something.eu > Date: Thu Dec 16 11:12:55 2010 +0200 Added longtable package for abbreviations commit 74069a151cce9c47484403c1db76e68e1360d8ee Author: Peter Smit < peter@something.eu > Date: Thu Dec 16 11:12:23 2010 +0200 Changed some headings in the introduction commit 94126f79fdc6f4927a3f270c152393377e9ef5a5 Author: Peter Smit < peter@something.eu > Date: Thu Dec 16 11:11:57 2010 +0200 Added abbreviations chapter 

All four commits change individual files, so merge conflicts cannot occur.

I would like to add 652b4 (added long column) to commit 94126 (added abbreviations). How can i do this?

+4
source share
2 answers

This situation is handled by interactive rebase . The standard warning that there is no overwriting of the history that was clicked applies. There is a worthy explanation in the Git book , but I personally believe that the rebase -i interface should be exactly upside down.

Start rebase by naming the parent of the earliest commit you need to change:

 $ git rebase -i 94126f7^ 

The editor pops up, listing commits in chronological order forward (so you need to turn your head upside down). It lists all the commits from HEAD to the child of the commit name, so you called it the parent:

 pick 94126f7 Added abbreviations chapter pick 74069a1 Changed some headings in the introduction pick 652b4c2 Added longtable package for abbreviations pick 326f35d Small editing in ASR chapter 

What you want to do is squash commit 652b4c2 to 94126f7, so you change its command to "squash" and move it right after the last one:

 pick 94126f7 Added abbreviations chapter squash 652b4c2 Added longtable package for abbreviations pick 74069a1 Changed some headings in the introduction pick 326f35d Small editing in ASR chapter 

Save and exit; the next editor that appears will be for the combined commit message. You can change it however you want, then when you exit it, it will finish rebase.

Conflicts on reboot can be annoying (some fixes just won’t commute), and merging can be especially ugly, but there will be no problems reordering files.

+10
source

If you don't push these commits yet, do git rebase --interactive (see Interactive Reboxing ).
You can make these two commits one.

+3
source

Source: https://habr.com/ru/post/1332325/


All Articles