Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
385 views
in Technique[技术] by (71.8m points)

Remove a git commit which has not been pushed

I did a git commit but I have not pushed it to the repository yet. So when I do git status, I get '# Your branch is ahead of 'master' by 1 commit.

So if I want to roll back my top commit, can I just do:

git reset --hard eb27bf26dd18c5a34e0e82b929e0d74cfcaab316

given that when I do git log I get:

commit eb27bf26dd18c5a34e0e82b929e0d74cfcaab316
Date:   Tue Sep 29 11:21:41 2009 -0700


commit db0c078d5286b837532ff5e276dcf91885df2296
Date:   Tue Sep 22 10:31:37 2009 -0700
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

IF you have NOT pushed your changes to remote

git reset HEAD~1

Check if the working copy is clean by git status.

ELSE you have pushed your changes to remote

git revert HEAD

This command will revert/remove the local commits/change and then you can push


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...