Removing a commit with git
Possible Duplicate:
How to delete a 'git commit'
I am new to git and I encountered a situation which I need some help with. I cloned a remote repository to my PC, and then opened a new branch named "meir".
For practice purposes I first commited some changes I've made on a file. Afterwards, I changed the file the way I wanted it to be and commited again. Then I pushed my local branch to the remote repository.
The problem is that I have the first commit which was a test and I would not like it to be on the remote server. I thought about 2 possible ways to fix it:
What commands do I need to run to achieve each of the options?
Thanks, Meir
Generally speaking, you should not change commit history after you have pushed to public branch in a remote repository. It will cause pain to people who have pulled/cloned from the remote repository.
But if you really want to do it, you could use interactive rebase and forced push:
Another option is to remove the remote branch 'meir' with git push origin :meir
, resturcture your local repository with git rebase -i
and then push as normally.
There are multiple ways of doing it, but none of them are recommnded though So, Use them at your own risk.
Pushing one of the commits
Using rebase
If you have 2 commits & wish to push only one of them, which is not the latest one.
With this only changes corresponding to 2nd Commit Id will be pushed & your latest commit will be not pushed.
But, if the latest commit has to be pushed and not the 2nd Commit, you have to first reverse the commits
In the editor that opens up, you should see two lines representing your commits 53259b225 & 227552392 like
pick 227552392 blah blah pick 53259b225 blah blah
Reorder these 2 lines to look like
pick 53259b225 blah blah pick 227552392 blah blah
and then save the file.
With this you are essentially changing the order of your commits. If you worked on different sets of files in both the commits, then this would a relatively easier process. If not then you may have some merging to do.
If at any point of time if you think you have messed up, then you can give the command
Using squash
As you see, this can also be used to merge few commits into one.
链接地址: http://www.djcxy.com/p/9004.html上一篇: 处理提交5提交前。 如何做到最好?
下一篇: 使用git删除提交