Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
2 answers
For another perspective, I use TortoiseGit (https://tortoisegit.org/) on Windows a fair bit:
-
Checkout the branch.
-
Open the log window (Git Show log).
-
Right-click on the commit/branch that you want to reset to, and choose Reset...:
-
In that dialog, you can choose soft, hard, or mixed reset. I usually pick hard.
-
Once done, pushing may be troublesome like lizuki said, but if no one else has pushed that branch in the meantime, I like to push with the "force with lease" option checked. With it checked, you can only push if there are no new (as in, from other people) commits on the branch on the remote. But if you need to force it, just coordinate with others working off that branch.
With git reset
, but first, you may want to save the current state in another branch:
$ git switch main
$ git branch backup-of-main
Now the (perhaps messed up) state is safely stored in branch backup-of-main
, and you can always just switch back to it and have another swing.
To move main
to an earlier commit:
$ git switch main
$ git reset --hard <commit-hash>
You might still run into issues when pushing main
to a remote that has already seen the more futuristic states. In this case, you need to force push:
$ git push --force
When you are absolutely sure that it worked out as you planned, you may consider removing the backup-of-main
branch. See this question for how.
0 comment threads