Search code examples
gitgithubandroid-sourcegerrit

Removing a commit in remote from local


I'm currently working with git on building aosp. The task I wish to perform is removing a commit from my local that's already been pushed to the remote by someone else.

After some heavy Googling I came across git reset --hard HEAD~1, which I thought did what I wanted it to do after typing git log and not seeing the commit.

When I went to brunch the build, it failed, stating that the build at the change wasn't clean. Noting that I'd completed a build only 30mins prior to this, I know the initial build wasn't the issue.

Is there an appropriate way to do this?


Solution

  • You can revert to a previous commit by using checkout command, git checkout accepts commit hash/ID, just run git log search for the commit you want to revert to and copy the previous commit hash and run the following command:

    git checkout COMMIT_HASH   # This will revert back git history just before the commit
    

    And after that if you want to go back to just run

    git checkout HEAD