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
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Git: Undoing last few commits

  • 01-11-2019 2:26pm
    #1
    Registered Users, Registered Users 2 Posts: 14,081 ✭✭✭✭


    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, Registered Users 2 Posts: 2,824 ✭✭✭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, Registered Users 2 Posts: 14,081 ✭✭✭✭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, Registered Users 2 Posts: 14,081 ✭✭✭✭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, Registered Users 2 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, Registered Users 2 Posts: 14,081 ✭✭✭✭mrcheez


    I got it sorted: git push -f


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


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

    One of the better Google image searches.


  • Registered Users, Registered Users 2 Posts: 2,040 ✭✭✭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, Registered Users 2 Posts: 14,081 ✭✭✭✭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