Posted about 6 years ago. Visible to the public. Repeats. Linked content.

How to split up a git commit

Quick steps

  1. git rebase -i -> mark your commit with edit
  2. git reset HEAD~ (remove the marked commit, but keep its changes)
  3. Make several commits
  4. git rebase --continue

Detailed instructions

Basically, you will review the last n commits and stop at the splittable commit. Then you'll undo that commit and put its changes into new commits at your liking.

  1. Review commits (rebase)

    git rebase -i HEAD~3 # or git rebase -i origin/master

    Git will give you a list of commits, youngest at the bottom. It will look like this:

    pick 27f2769 Do something pick b891fd1 Do many things pick da3c35c Do something else
  2. Mark the splittable commit: replace pick with edit. Save/:wq/exit.

    Git will now re-apply the commits one by one. Once it has applied the splittable commit (say, b891fd1), it will stop and wait for you to make changes

  3. Unwrap the commit, i.e. drop the commit, but keep all its file changes:

    git reset HEAD~
  4. Prepare the first new commit by adding files or parts of files:

    # Examples: git add vendor # or git add config/database.yml # or git add -p
  5. Once you're done, commit:

    git commit -m 'My commit message'
  6. Repeat steps 4 & 5 until no changes are left.

  7. Finish by telling git to continue the rebase:

    git rebase --continue

Flaky tests are tests that sometimes fail for no obvious reason. They are the plague of many end-to-end (E2E) test suites that automate the browser through tools like Capybara and Selenium.

Join our free training event and learn to fix any flaky test suite, even in large legacy applications.

Owner of this card:

Dominik Schöler
Last edit:
over 4 years ago
by Besprechungs-PC
About this deck:
We are makandra and do test-driven, agile Ruby on Rails software development.
License for source code
Posted by Dominik Schöler to makandra dev
This website uses short-lived cookies to improve usability.
Accept or learn more