7

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?

Community
  • 1
  • 1
hellomello
  • 8,219
  • 39
  • 151
  • 297

2 Answers2

4

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

Vasfed
  • 18,013
  • 10
  • 47
  • 53
  • When you mean detached state, is that when you're in the checkout of another commit? – hellomello Dec 10 '15 at 16:50
  • Yes, it is when you're in checkout of commit, that is not on head of any branch. Git will warn on upon checkout. The point is that if you commit to detached tree and not make a branch - these new commits will be lost – Vasfed Dec 10 '15 at 16:51
4

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.

g24l
  • 3,055
  • 15
  • 28
  • This actually looks great! I'll try it out and report back of any issues or questions! – hellomello Dec 10 '15 at 17:09
  • I was trying this out and was going down my commits with `git bisect bad` and then an error came up `error: Your local changes to the following files would be overwritten by checkout:` What would I do now? – hellomello Dec 10 '15 at 17:28
  • And then I typed in `git bisect reset` now it gave me a modified page, and said `Previous HEAD position was b2f1d32` but that's not the most recent commit? Did I do something wrong? – hellomello Dec 10 '15 at 17:32
  • If you had unsaved changes before you started , at some point they maybe overwritten. To avoid this, you can abort the bisect and do get bisect reset. Then you can stash your local changes, with git stash. once you are finished and you want to continue working, you should do git stash pop to restore your work. – g24l Dec 10 '15 at 21:03
  • @hellomello, check the comment above. – g24l Dec 10 '15 at 21:32