GIT How to remove unnecessary commits without creating an intermediate `branch` a?

Question:

How can I solve the following problem without creating an intermediate branch a?

I switched to master and did

git checkout master
git fetch --all
git merge origin master
git merge origin another_branch

and in another_branch found the 3rd commit unnecessary for me. But everything is already on master e. How can I delete, for example, the 3rd and 5th commits so as not to damage the rest?

1) That is, how to do push without them?

2) And if the push has already been made, how to fix the situation?

Please write down the steps by which you can implement this.

Answer:

git reset – if not pushed to server, this will remove the commit

git revert – if pushed to the server, this will create another commit which will be the opposite of the previous one (will revert all changes)

source (details)

Scroll to Top