Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Git: Undoing last few commits

Options
  • 01-11-2019 3:26pm
    #1
    Registered Users Posts: 13,758 ✭✭✭✭


    I'm using Visual Studio 2019 and want to undo the last 7 commits so that the 8th commit is the latest and only one going forward (I assume it becomes the HEAD).

    I've got the list of commits on screen and when I right-click the 8th commit I get options:

    - Revert

    - Reset with sub -options --mixed (Keep changes) OR --hard (Delete changes)



    I don't want any of the changes and the repo isn't Public (only within team), so is Reset --hard the one I want?


Comments

  • Registered Users Posts: 2,799 ✭✭✭mightyreds


    if you revert it will make a new commit undoing all the previous commits, this is the safest way

    if you reset it will remove those commits from history, this can cause problems for others who have pulled since they have those commits locally and now they are gone


  • Registered Users Posts: 13,758 ✭✭✭✭mrcheez


    mightyreds wrote: »
    if you revert it will make a new commit undoing all the previous commits, this is the safest way

    if you reset it will remove those commits from history, this can cause problems for others who have pulled since they have those commits locally and now they are gone

    I'm the only one working on this at the moment, so the reset should be fine. In retrospect I probably should have created a new branch but I assumed the path I was working on was fine so decided just to continue.

    Now I just want to remove all trace of the recent commits.. so reset --hard will remove any new files etc right?


  • Registered Users Posts: 13,758 ✭✭✭✭mrcheez


    So I did reset --hard, but now I have the unwanted commits listed as "Incoming Commits", so that when I do a Sync I'll be back to where I was.

    How do I wipe these unwanted commits so that they are no longer listed as Incoming?


  • Registered Users Posts: 7,157 ✭✭✭srsly78


    You don't. Rewriting history is bad.

    Git saves all history, nothing ever really gets deleted.

    You can bypass this ofc but it never ends well ðŸ˜႒


  • Registered Users Posts: 13,758 ✭✭✭✭mrcheez


    I got it sorted: git push -f


  • Advertisement
  • Registered Users Posts: 6,236 ✭✭✭Idleater


    mrcheez wrote: »
    I got it sorted: git push -f

    One of the better Google image searches.


  • Registered Users Posts: 2,024 ✭✭✭Colonel Panic


    "Rewriting history is bad" is just one of those things people always say without really thinking about it.

    Rewriting a shared branch and using a force push is bad.


  • Registered Users Posts: 13,758 ✭✭✭✭mrcheez


    Well obviously I don't do it regularly hence me posting here as I wasn't able to find a clear definition on which option to use.

    Yah normally I'd just commit the updates to get it back to the way it was but it didn't matter this time around as I'm working solo on this for now plus it would have required considerable effort.

    Anyway I got the info I requested so unfollowing, thanks all


Advertisement