'Difference between methods to delete last git commit
Please, what is the difference between git rebase -i and git reset --soft HEAD^ ? what does each one implies in the background ? When to use each one ?
Solution 1:[1]
This is pretty well covered elsewhere, so I'm going to keep this answer short.
The git rebase command is about copying (some) commits to new-and-improved commits that we wish to use instead. Because there are so many options—especially the highly flexible --interactive or -i option—this gets very complex.
The git reset command is itself also complicated, but in this particular usage, is about discarding some commits. If you should subsequently make new commits, and if those new commits are in effect new-and-improved copies of the old commits, this reset-and-commit sequence also results in copying old commits to new-and-improved commits that we will use instead.
The old git rebase was a very fancy shell script that used git reset followed by git cherry-pick. It has since been rewritten into a very fancy C program that, internally, uses git reset followed by git cherry-pick: that is, its external behavior is mostly the same as before, and while the underlying implementation has been rewritten, it's still very similar.
Hence, depending on how you use git rebase -i, and how you use git reset --soft, you can get exactly the same effect. Use whichever one you prefer, as long as it produces the effect you want.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | torek |
