开发者

Roll back my github fork to an earlier commit

I have forked a repo on github and I now want to roll my fork back to a known commit. I can get the right files locally using

git reset --hard HEAD~1

but then what?

How can I then commit that version back? Do I add all the current files to the staging area and then commit and push?

EDIT: Or is what I really need a branch? Basically, the HEAD of the repo I 开发者_如何学Coriginally forked uses some new dependencies that I can't rely on, so I want to take the code from that repo and shift it all back X days in the commit history. I want the newly rolled-back code to be available on github so I can include it as a Gem in my Rails 3 app.

Is that better and can somebody show me how to do that?


You will have to force a push after the reset:

git push origin +master

However, it is not a good idea to force push to a previous commit if the repository is public.

If you do not want to reset the local repository, but want the public one to go back a commit, use a refspec like master~1:master:

git push origin +master~1:master

A branch with commits that do not contain the dependencies can be used in your scenario. For example consider the branch's name to be without_dependencies:

git branch without_dependencies master~1
git push origin without_dependencies

Everyone will be able to see this new branch and work on it.


Another solution would be to (after your local reset) git pull -s ours origin master which will discard all changes from the merge, making the result your local HEAD, but leaving the history intact. You'd have a crappy commit sitting there, but you'd be able to then continue with git push, etc, how you normally would.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜