Skip to main content
added 102 characters in body; added 3 characters in body
Source Link
jonrsharpe
  • 119.9k
  • 29
  • 253
  • 455

You can do an interactive rebase, per [1]the docs and [2]this blog post.

  1. Start an interactive rebase:

    Start an interactive rebase:

    git rebase -i HEAD~n
    

    (where n is how far do you want to go back in history)

  2. Your default editor will open. At the top, a list of your latest n commits will be displayed, in reverse order. Eg:

    pick a5f4a0d commit-1
    pick 19aab46 commit-2
    pick 1733ea4 commit-3
    pick 827a099 commit-4
    pick 10c3f38 commit-5
    pick d32d526 commit-6
    
  3. Specify squash (or the shortcut s) for all commits you want to squash. E.g.:

    pick a5f4a0d commit-1
    pick 19aab46 commit-2
    squash 1733ea4 commit-3
    squash 827a099 commit-4
    pick 10c3f38 commit-5
    pick d32d526 commit-6
    

    Git applies both that change and the change directly before it and makes you merge the commit messages together.

  4. Save and exit.

  5. Git will apply all changes and will open again your editor to merge the three commit messages. You can modify your commit messages or leave it as it is (if so, the commit messages of all commits will be concatenated).

  6. You're done! The commits you selected will all be squashed with the previous one.

git rebase -i HEAD~n (where ’n’ is how far do you want to go back in history)
  1. Your default editor will open. At the top, a list of your latest n commits will be displayed, in reverse order. Eg:
pick a5f4a0d commit-1
pick 19aab46 commit-2
pick 1733ea4 commit-3
pick 827a099 commit-4
pick 10c3f38 commit-5
pick d32d526 commit-6
  1. Specify squash (or the shortcut s) for all commits you want to squash. Eg:
pick a5f4a0d commit-1
pick 19aab46 commit-2
squash 1733ea4 commit-3
squash 827a099 commit-4
pick 10c3f38 commit-5
pick d32d526 commit-6

Git applies both that change and the change directly before it and makes you merge the commit messages together.

  1. Save and exit.

  2. Git will apply all changes and will open again your editor to merge the three commit messages. You can modify your commit messages or leave it as it is (if so, the commit messages of all commits will be concatenated).

  3. You're done! The commits you selected will all be squashed with the previous one.

You can do an interactive rebase [1] [2].

  1. Start an interactive rebase:
git rebase -i HEAD~n (where ’n’ is how far do you want to go back in history)
  1. Your default editor will open. At the top, a list of your latest n commits will be displayed, in reverse order. Eg:
pick a5f4a0d commit-1
pick 19aab46 commit-2
pick 1733ea4 commit-3
pick 827a099 commit-4
pick 10c3f38 commit-5
pick d32d526 commit-6
  1. Specify squash (or the shortcut s) for all commits you want to squash. Eg:
pick a5f4a0d commit-1
pick 19aab46 commit-2
squash 1733ea4 commit-3
squash 827a099 commit-4
pick 10c3f38 commit-5
pick d32d526 commit-6

Git applies both that change and the change directly before it and makes you merge the commit messages together.

  1. Save and exit.

  2. Git will apply all changes and will open again your editor to merge the three commit messages. You can modify your commit messages or leave it as it is (if so, the commit messages of all commits will be concatenated).

  3. You're done! The commits you selected will all be squashed with the previous one.

You can do an interactive rebase, per the docs and this blog post.

  1. Start an interactive rebase:

    git rebase -i HEAD~n
    

    (where n is how far do you want to go back in history)

  2. Your default editor will open. At the top, a list of your latest n commits will be displayed, in reverse order. Eg:

    pick a5f4a0d commit-1
    pick 19aab46 commit-2
    pick 1733ea4 commit-3
    pick 827a099 commit-4
    pick 10c3f38 commit-5
    pick d32d526 commit-6
    
  3. Specify squash (or the shortcut s) for all commits you want to squash. E.g.:

    pick a5f4a0d commit-1
    pick 19aab46 commit-2
    squash 1733ea4 commit-3
    squash 827a099 commit-4
    pick 10c3f38 commit-5
    pick d32d526 commit-6
    

    Git applies both that change and the change directly before it and makes you merge the commit messages together.

  4. Save and exit.

  5. Git will apply all changes and will open again your editor to merge the three commit messages. You can modify your commit messages or leave it as it is (if so, the commit messages of all commits will be concatenated).

  6. You're done! The commits you selected will all be squashed with the previous one.

added 812 characters in body
Source Link
ludovico
  • 2.3k
  • 1
  • 14
  • 35

You can do an interactive rebase: [1] [2].

  • Start interactive rebase:
  1. Start an interactive rebase:
git rebase -i HEAD~n (where ’n’ is how far do you want to go back in history)
  • Specify squash for all commits you want to squash:
  1. Your default editor will open. At the top, a list of your latest n commits will be displayed, in reverse order. Eg:
pick a5f4a0d commit-1
pick 19aab46 commit-2
pick 1733ea4 commit-3
pick 827a099 commit-4
pick 10c3f38 commit-5
pick d32d526 commit-6
  1. Specify squash (or the shortcut s) for all commits you want to squash. Eg:
pick a5f4a0d commit-1
pick 19aab46 commit-2
squash 1733ea4 commit-3
squash 827a099 commit-4
pick 10c3f38 commit-5
pick d32d526 commit-6

Git applies both that change and the change directly before it and makes you merge the commit messages together.


More info:

https://git-scm.com/book/en/v2/Git-Tools-Rewriting-History#_squashing

https://thoughtbot.com/blog/git-interactive-rebase-squash-amend-rewriting-history#squash-commits-together

  1. Save and exit.

  2. Git will apply all changes and will open again your editor to merge the three commit messages. You can modify your commit messages or leave it as it is (if so, the commit messages of all commits will be concatenated).

  3. You're done! The commits you selected will all be squashed with the previous one.

You can do an interactive rebase:

  • Start interactive rebase:
git rebase -i HEAD~n (where ’n’ is how far do you want to go back in history)
  • Specify squash for all commits you want to squash:

Git applies both that change and the change directly before it and makes you merge the commit messages together.


More info:

https://git-scm.com/book/en/v2/Git-Tools-Rewriting-History#_squashing

https://thoughtbot.com/blog/git-interactive-rebase-squash-amend-rewriting-history#squash-commits-together

You can do an interactive rebase [1] [2].

  1. Start an interactive rebase:
git rebase -i HEAD~n (where ’n’ is how far do you want to go back in history)
  1. Your default editor will open. At the top, a list of your latest n commits will be displayed, in reverse order. Eg:
pick a5f4a0d commit-1
pick 19aab46 commit-2
pick 1733ea4 commit-3
pick 827a099 commit-4
pick 10c3f38 commit-5
pick d32d526 commit-6
  1. Specify squash (or the shortcut s) for all commits you want to squash. Eg:
pick a5f4a0d commit-1
pick 19aab46 commit-2
squash 1733ea4 commit-3
squash 827a099 commit-4
pick 10c3f38 commit-5
pick d32d526 commit-6

Git applies both that change and the change directly before it and makes you merge the commit messages together.

  1. Save and exit.

  2. Git will apply all changes and will open again your editor to merge the three commit messages. You can modify your commit messages or leave it as it is (if so, the commit messages of all commits will be concatenated).

  3. You're done! The commits you selected will all be squashed with the previous one.

Source Link
ludovico
  • 2.3k
  • 1
  • 14
  • 35

You can do an interactive rebase:

  • Start interactive rebase:
git rebase -i HEAD~n (where ’n’ is how far do you want to go back in history)
  • Specify squash for all commits you want to squash:

Git applies both that change and the change directly before it and makes you merge the commit messages together.


More info:

https://git-scm.com/book/en/v2/Git-Tools-Rewriting-History#_squashing

https://thoughtbot.com/blog/git-interactive-rebase-squash-amend-rewriting-history#squash-commits-together