Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

git - How to delete commit that is pushed to the remote repository?

A local branch:-

'feature/100'

And Remote branches:-

'master'

'Version2'

Accidently,

  1. I have merged my feature branch 'feature/100' to the master
  2. Also pushed it to the remote repository.

But in real 'feature/100' should have been merged into remote branch 'Version2'

How I fixed it (partially):-

i have merged the feature branch 'feature/100' to the remote branch 'Version2' and pushed it to the server.

git checkout Version2
git merge --squash feature/100
git add .
git commit -m 'New message'

But I want to delete the last push I have merged and commit to the master branch. How?

Side Note I am only one working on this project.. So even if pushed commit is deleted it won't harm anyone else

See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

You can either:

Revert your change

git revert HEAD

This will create a new commit that reverts the changes that you just pushed up to master. This is the safest option because other people may have already pulled down the change that you have pushed up.

Change your commit history and force push the change

You can remove the commit that you just pushed up with:

git reset --hard HEAD~1

git push origin master --force

You don't want to do this unless you're absolutely sure that no one has pulled down your changes from master.

For more info, see Delete commits from a branch in Git


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...