Skip to main content

Squashing multiple commits into one

(2017-09-14)

Squashing multiple commits into one:

git log shows you the history:

[dave@store02 ansible]$ git log
commit 777574670a1c5dccc91f12320a811759163e4ff9
Author: David Mackintosh <dave@gridway.net>
Date:   Thu Sep 14 12:20:31 2017 -0400

    davem.sh handles centos and fedora now

commit 22a613ea808bd00ab86b1c432968a5207c814f38
Author: David Mackintosh <dave@gridway.net>
Date:   Thu Sep 14 11:36:51 2017 -0400

    fix fedora version check

commit e5d4c928c8bdfed6afdfd35b9c5f50883326f99a
Author: David Mackintosh <dave@store02.gridwayit.local>
Date:   Thu Sep 14 11:23:46 2017 -0400

    back to post-fedora version of davem.sh

commit 241e3d9efc0842dfb91553691790d4c487e9c072
Author: David Mackintosh <dave@store02.gridwayit.local>
Date:   Thu Sep 14 11:23:10 2017 -0400

    pre-fedora version of davem.sh

commit 4995a0fe82ba1491a55e8f7af3ad67d305533148
Author: David Mackintosh <dave@store02.gridwayit.local>
Date:   Thu Sep 14 11:14:32 2017 -0400

    Initial commit

git reset brings the repository pointers back to a given version:

[dave@store02 ansible]$ git reset 241e3d9efc0842dfb91553691790d4c487e9c072
Unstaged changes after reset:
M       roles/environment/davem.sh

Now you can just commit the changes in one go:

[dave@store02 ansible]$ git commit -m "Change centos/redhat/fedora and version detection" roles/environment/davem.sh
[master 2c0d620] Change centos/redhat/fedora and version detection
 1 files changed, 36 insertions(+), 16 deletions(-)

...and observe the changes:

[dave@store02 ansible]$ git log
commit 2c0d620f012d2c931e287a779fb4892a876aa7d6
Author: David Mackintosh <dave@gridway.net>
Date:   Thu Sep 14 12:28:18 2017 -0400

    Change centos/redhat/fedora and version detection

commit 241e3d9efc0842dfb91553691790d4c487e9c072
Author: David Mackintosh <dave@store02.gridwayit.local>
Date:   Thu Sep 14 11:23:10 2017 -0400

    pre-fedora version of davem.sh

commit 4995a0fe82ba1491a55e8f7af3ad67d305533148
Author: David Mackintosh <dave@store02.gridwayit.local>
Date:   Thu Sep 14 11:14:32 2017 -0400

    Initial commit