Reis mit Eis Reis mit Eis - 3 months ago 13
Git Question

Removing 1. commit before pushing

I have made an accidentally changes in core files and saved it and made a commit. and make another changes and created new commit. and my real project is in commit 1.

commit e8e7a9....
Author:
Date:

Commit message 1 (Real Project)
----------------------------------------------
commit e8e7a9....
Author:
Date:

Commit message 2 (Remove this one)
----------------------------------------------
commit e8e7a9....
Author:
Date:

Commit message 3 ( It must be there)


I only want to delete commit, but If I do it, am I going to update the removed commit or how danger is it and how can I do it?

is it correct if I use ?

git reset --soft HEAD~2


UPDATE:

After I must push to remote git server a new branch with the 2.Commit only if possible?

D J D J
Answer

It's ok to use

git reset --soft HEAD~2

This will unstage your changes in last two commits, which does not mean you have lost your changes. After this you can use

git status

to view all the changes. You can remove the ones which are not required and then commit the required ones.

git add <the_required_files>
git commit -m "my commit message"

You can push afterwards just like you did

git push <remote_name> <branch_name>