I have 2 commits that I did not push:
$ git status # On branch master # Your branch is ahead of 'faves/master' by 2 commits.
How can I roll back my first one (the oldest one), but keep the second one?
$ git log commit 3368e1c5b8a47135a34169c885e8dd5ba01af5bb ... commit baf8d5e7da9e41fcd37d63ae9483ee0b10bfac8e ...
Do I just need to do:
git reset --hard baf8d5e7da9e41fcd37d63ae9483ee0b10bfac8e
The safest and probably cleanest way to go is to rebase interactively.
From there you can squash commits, which puts one or more commits together into the previous commit. To completely delete a commit from the history, delete the line from the list.
You can revert a commit with
git revertbut its going to add more commit messages to the history, which may be undesirable. Use the
-nparameter to tell Git not to commit the revert right away. You can rebase interactively and squash those on up to a previous commmit to keep things clean.
If the two commits you're working with here affect the same file(s), you may see a merge conflict.
Resetting the repository with
git reset --hardshould be done with care, as it cannot be undone.
Rewriting history should be done with care.