Monday, July 27, 2015

Git rebase and squash commits

* Check commit logs as follows:

$ git log

commit da274bb605a962fa02ae8fba2da27b934b59d68d
Author: izeye <izeye@naver.com>
Date:   Tue Jul 28 11:55:38 2015 +0900

    Fix typos.

commit 0e5f855954a69dd05128442bf9c996efc8d35f0d
Author: izeye <izeye@naver.com>
Date:   Tue Jul 28 11:47:52 2015 +0900

    Fix typos.

commit 32128a6ac2390250d9e0b933618177846fb7bef0
Author: Stephane Nicoll <snicoll@pivotal.io>
Date:   Mon Jul 27 16:02:03 2015 +0200

    Polish
...

* `git rebase` with the base commit as follows:

$ git rebase -i 32128a6ac2390250d9e0b933618177846fb7bef0

pick 0e5f855 Fix typos.
squash da274bb Fix typos.

* Type `:wq` and change commit messages as follows:

# This is a combination of 2 commits.
# The first commit's message is:

Fix typos.

# This is the 2nd commit message:

#Fix typos.

* Type `:wq` again.

* Check commit logs again as follows:

$ git log

commit d51d6b7e8d21c60a6ac9e6e6e60847c112514998
Author: izeye <izeye@naver.com>
Date:   Tue Jul 28 11:47:52 2015 +0900

    Fix typos.

commit 32128a6ac2390250d9e0b933618177846fb7bef0
Author: Stephane Nicoll <snicoll@pivotal.io>
Date:   Mon Jul 27 16:02:03 2015 +0200

    Polish

If you want to push it to the remote repository,

do as follows:

$ git push -f

Reference:
https://github.com/edx/edx-platform/wiki/How-to-Rebase-a-Pull-Request

No comments:

Post a Comment