Mithun Sasidharan
Mithun Sasidharan

Reputation: 20920

Push a new commit without previous commit dependencies

I made a commit in my local system and pushed it for review..

Now i want to make another commit and push it and make sure the first one is not a dependency. How can i do that?

Please help me with the commands.

Upvotes: 2

Views: 2993

Answers (2)

CharlesB
CharlesB

Reputation: 90316

Branches are great for this. You want to make another commit based on the parent of the commit you pushed, so that it doesn't contain its changes.

Say your commit is B and its parent is A. You reset the working copy to commit A (your work won't be lost since it is pushed) by doing

git checkout HEAD~

HEAD~ meaning the parent of current branche's commit.

Then make the changes, and commit them to a new branch:

git checkout -b other_feature_branch
git commit

Upvotes: 1

Artefacto
Artefacto

Reputation: 97835

You have several options. You can simply discard the last commit (you'll lose it and have to use reflog to recover it unless you save the hash):

git reset --hard HEAD~1

Alternatively you can do a soft reset and stash your last commit:

git reset --soft HEAD~1
git stash

Or you can branch the commit before and work in that branch:

git checkout -b newbranch HEAD~1

Upvotes: 4

Related Questions