Throw away local commits in Git

前端 未结 20 1671
遥遥无期
遥遥无期 2020-12-02 03:08

Due to some bad cherry-picking, my local Git repository is currently five commits ahead of the origin, and not in a good state. I want to get rid of all these commits and st

20条回答
  •  [愿得一人]
    2020-12-02 03:40

    If you get your local repo into a complete mess, then a reliable way to throw away local commits in Git is to...

    1. Use "git config --get remote.origin.url" to get URL of remote origin
    2. Rename local git folder to "my_broken_local_repo"
    3. Use "git clone " to get fresh local copy of remote git repository

    In my experience Eclipse handles the world changing around it quite well. However, you may need to select affected projects in Eclipse and clean them to force Eclipse to rebuild them. I guess other IDEs may need a forced rebuild too.

    A side benefit of the above procedure is that you will find out if your project relies on local files that were not put into git. If you find you are missing files then you can copy them in from "my_broken_local_repo" and add them to git. Once you have confidence that your new local repo has everything you need then you can delete "my_broken_local_repo".

提交回复
热议问题