Is there anyway to delete/undo like the last 5 commits? I have an issue that is too muddled up to fix so I would rather go back to a commit that i know is stable
Asked
Active
Viewed 88 times
1 Answers
2
Issue this command:
git reset --soft HEAD~6
If you want to loose changes:
git reset --hard HEAD~6

Antonio Petricca
- 8,891
- 5
- 36
- 74
-
what is HEAD~6 ? – BranOIE May 26 '21 at 15:53
-
`HEAD` is a pointer to your top commt. By `HEAD~6` we are telling to **git** to reference back to 6 commits as last good commit. – Antonio Petricca May 26 '21 at 15:55
-
Ah i see, thank you! – BranOIE May 26 '21 at 15:56
-
2Please accept my solution if you think it is correct. – Antonio Petricca May 26 '21 at 15:56
-
1I can only do so in 9 minutes, I'll do so then! – BranOIE May 26 '21 at 15:57
-
When I do this, and want to push a new change, it tells me I must pull the commits i undid again – BranOIE May 26 '21 at 16:01
-
That means that you have commits not yet pushed. Try `git stash save && git pull && git stash pop`. – Antonio Petricca May 26 '21 at 16:03
-
That brought me back to square one unfortunately – BranOIE May 26 '21 at 16:04
-
Now you are addressing a different issue from your original post. I suggest you to open a new one with all the details and issued commands. – Antonio Petricca May 26 '21 at 16:05
-
_When I do this, and want to push a new change, it tells me I must pull the commits i undid again_ I'd actually say this sounds like you've already pushed some of the changes you rolled back to the remote already. You _may_ need to force push, but make _sure_ you know what you're doing because you'll be irreversibly destroying history. – Alexander Nied May 26 '21 at 16:12