Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

reverse back to certain commit and test what the issue?

Is there a way to keep all my changes now, and still reverse back my app to a certain commit and start going through all other commits to see which one caused an issue in my app?

I did a lot of changes, and it would take me a long time to check everything, so I want to get my previous commits and when I find the issue, I'll revert back to most recent commit and then just apply the necessary changes.

There's this answer here: git revert back to certain commit but I still want to keep all my recent changes, can someone walk me through the thought process?

I'm thinking if I commit my most recent changes now, its in bitbucket, then use the method: git reset --hard {commit numbers} and just keep going through my list of commits, and when I find the issue, git reset --hard {most recent commit} this will bring me back to most recent state?

like image 910
hellomello Avatar asked Dec 10 '15 16:12

hellomello


People also ask

What happens if you revert a revert commit?

Unlike git reset , git revert doesn't remove the commit from the project history but inverts the changes introduced by the selected commit and appends a new commit with the resulting inverse content.

How do you reverse to a specific commit?

To undo changes associated with a specific commit, developers should use the git revert command. To undo every change that has happened since a given commit occurred, use git reset.

What does it mean to reverse a commit?

James Gallagher - December 29, 2020. The git revert command will undo a commit so you can return a repository to the previous commit. Instead of deleting the commit, revert will create a new commit that will reverse the changes of a published commit. This preserves the initial commit as a part of the project's history.

How do you revert back to a commit in git?

To revert a commit with GitKraken, simply right-click on any commit from the central graph and select Revert commit from the context menu.


Video Answer


2 Answers

There is a command for what you want to do and it is called git bisect which uses binary search to find the commit that has not been working. The process is

git bisect start

git bisect bad

git bisect <your last good commit here>

Here is a fairly easy to read guide.

This will permit you to find which commit caused the issue.

like image 139
g24l Avatar answered Sep 19 '22 21:09

g24l


Commit all uncommited changes, clean the tree of untracked files, then you can just do

git checkout <some_commit_sha>

to go to that specific commit, and then git checkout master (or other branch) to get back.

Just do not commit anything, while being in 'detached' state, if you must - you can start a branch there and proceed as usual

like image 35
Vasfed Avatar answered Sep 17 '22 21:09

Vasfed