Timeline for How can I revert multiple Git commits?
Current License: CC BY-SA 4.0
10 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Dec 6, 2023 at 14:27 | comment | added | leymannx |
If this includes merge commits then git revert D C B -m 1 worked for me. The -m option specifies the mainline parent, which is usually the branch you merged into. For most cases, you'll want to use -m 1 .
|
|
Oct 12, 2020 at 17:13 | history | edited | rogerdpack | CC BY-SA 4.0 |
another permutation :)
|
Oct 12, 2020 at 16:38 | history | edited | rogerdpack | CC BY-SA 4.0 |
Use can use specific commits too apparently...
|
Oct 12, 2020 at 14:04 | comment | added | rogerdpack |
Sure enough, if you do this without --no-commit it does them one at a time and you have to keep typing git revert --continue over and over for each one...dang I was hoping git would have a friendly commit option like "do them all and list all the hashes for me in a single commit" but appears not :|
|
|
Nov 15, 2016 at 20:52 | comment | added | Resigned June 2023 |
@ChrisS My first thought would be to not use --no-commit (so you get a separate commit for each revert), and then squash all of them together in an interactive rebase. The combined commit message will contain all of the SHAs, and you can arrange them however you like using your favorite commit message editor.
|
|
Oct 1, 2015 at 18:33 | comment | added | Chris S | @kubi is there no way of including the SHAs in a commit message, using a single commit (your method but without having to manually enter the commits that were reverted)? | |
Apr 25, 2014 at 18:50 | comment | added | user456814 |
@Victor I fixed your commit range. The beginning of the range is exclusive, meaning it's not included. So if you want to revert the last 3 commits, you need to start the range from the parent of the 3rd commit, i.e. master~3 .
|
|
Apr 25, 2014 at 18:48 | history | edited | user456814 | CC BY-SA 3.0 |
Corrected commit range, the beginning of the range is exclusive (i.e., it's not included).
|
Jan 15, 2013 at 18:49 | comment | added | kubi |
git revert --no-commit HEAD~2.. is a slightly more idiomatic way to do it. If you're on master branch, no need to specify master again. The --no-commit option lets git try to revert all the commits at once, instead of littering the history with multiple revert commit ... messages (assuming that's what you want).
|
|
Jul 31, 2012 at 15:00 | history | answered | Victor | CC BY-SA 3.0 |