Skip to main content

commit-clean-examples

Clean up branch commits

Use git rebase -i <base-commit> to clean up commit history. Base commit is the last untouched commit and all commits after that are listed for change. The base-commit can be either commit-id, branch-name or tag.

[!NOTE] Commits in rebase view are in opposite order compared to git log output!

Examples

Example 1: Branch has fix commit for some previous commit.

$ git log --pretty=format:"%h%x09%s"

27a4aa2 fix: mavlink-router comment typo <-- fix for original commit (to be combined with the original commit)
92299c9 update saluki-firmware
1a9ac0c Update mavlink-router: flight logging via mavlink <-- original commit
e797eb6 ntrip-client:multi-arch support
4615a8b fog-hyper: from main and PX4 firmware file name updated <-- selected for base-commit
4717916 salukiv2: reliability patches kernel with 2CPU
32aa66d fog-hyper: timesync wait
  1. start interactive rebase
$ git rebase -i 4615a8b

pick e797eb6 ntrip-client:multi-arch support
pick 1a9ac0c Update mavlink-router: flight logging via mavlink <-- original commit
pick 92299c9 update saluki-firmware
pick 27a4aa2 fix: mavlink-router comment typo <-- fix for original commit (to be combined with the original commit)

  1. move (cut&paste) the fix commit right below the commit to be fixed:
pick e797eb6 ntrip-client:multi-arch support
pick 1a9ac0c Update mavlink-router: flight logging via mavlink <-- original commit
pick 27a4aa2 fix: mavlink-router comment typo <-- fix for original commit (to be combined with the original commit)
pick 92299c9 update saluki-firmware
  1. Change line command from 'pick' to 'fixup' (or to 'squash' in case you want to keep also the fix commit description)
pick e797eb6 ntrip-client:multi-arch support
pick 1a9ac0c Update mavlink-router: flight logging via mavlink <-- original commit
fixup 27a4aa2 fix: mavlink-router comment typo <-- fix for original commit (to be combined with the original commit)
pick 92299c9 update saluki-firmware
  1. Save changes and exit editor to proceed the rebase. See git log again:
$ git log --pretty=format:"%h%x09%s"

604e41c update saluki-firmware
8a96bf5 Update mavlink-router: flight logging via mavlink <-- original commit combined with the fix
e797eb6 ntrip-client:multi-arch support
4615a8b fog-hyper: from main and PX4 firmware file name updated
4717916 salukiv2: reliability patches kernel with 2CPU
32aa66d fog-hyper: timesync wait

Example 2: Branch has commit and revert commit for it

$ git log --pretty=format:"%h%x09%s"

026e146 Revert "add -f file" <-- revert for failing commit
f8471e3 update saluki-firmware
c864fee add -f file <-- failing commit
8a96bf5 Update mavlink-router: flight logging via mavlink
e797eb6 ntrip-client:multi-arch support <-- selected for base-commit
4615a8b fog-hyper: from main and PX4 firmware file name updated
4717916 salukiv2: reliability patches kernel with 2CPU
32aa66d fog-hyper: timesync wait
  1. start interactive rebase
$ git rebase -i e797eb6

pick 8a96bf5 Update mavlink-router: flight logging via mavlink
pick c864fee add -f file <-- failing commit
pick f8471e3 update saluki-firmware
pick 026e146 Revert "add -f file" <-- revert for failing commit
  1. Change commnd to 'drop' for those commits to be removed
pick 8a96bf5 Update mavlink-router: flight logging via mavlink
drop c864fee add -f file <-- failing commit
pick f8471e3 update saluki-firmware
drop 026e146 Revert "add -f file" <-- revert for failing commit
  1. Save changes and exit editor to proceed the rebase. See git log again. Both failing and revert commits are removed:
$ git log --pretty=format:"%h%x09%s"

e615123 update saluki-firmware
8a96bf5 Update mavlink-router: flight logging via mavlink
e797eb6 ntrip-client:multi-arch support
4615a8b fog-hyper: from main and PX4 firmware file name updated
4717916 salukiv2: reliability patches kernel with 2CPU
32aa66d fog-hyper: timesync wait