Rollback to Previous Commit - Github for MAC (a revert is already in progress)

后端 未结 1 718
一整个雨季
一整个雨季 2021-02-07 01:44

I think I\'ve messed up here.

I made a few changes to my code from a last commit adding new functionalities and realized that some other piece of code was now acting st

1条回答
  •  抹茶落季
    2021-02-07 02:30

    I do not know what github for Mac rollback does, but it seems that you would be better off using command line to resolve the issue at hand:

    git cherry-pick --abort - to stop any cherry-picking in progress

    git branch -va - will show you where are your pointers right now

    make sure your working directory is clean: git status - should not show any modified or staged files

    git stash - if anything modified still present

    git reset --hard your_local_branch github/remote_branch - make local branch reflect the state as it is on the remote side. obviously you don't need to do a reset if your current branch will point to the same commit as the remote. If you're in detached HEAD state (git status will tell you about it) then to come back to the normal state just checkout your local branch.

    Now decide what you actually want to achieve:

    I. get rid of the faulty commit?

    Use interactive rebase and remove the line with faulty commit, then force push to the remote repo on github (say faulty commit happened 10 commits ago)

    git rebase -i HEAD~11

    II. revert faulty commit? - wouldn't recommend to do that after some other commits, unless you're absolutely sure that the following commits didn't touch the same piece of code. This will effectively create a reverse commit (if line was added by faulty commit it will be removed by revert and vice versa)

    git revert {commit-sha1}

    III. Amend faulty commit? use interactive rebase, but instruct it to stop at faulty commit for amending. When it does stop edit the change and continue rebasing, then force push to the remote branch (use rebase command from the solution I )

    After you're done if anything was stashed use git stash pop to bring the changes back.

    hope that helps!

    0 讨论(0)
提交回复
热议问题