0

In cloud9 IDE, I am doing simple rails app in master branch. I decided to experiment a little, so I created new branch like this:

git checkout -b experiment-branch

Then I created some controllers, models etc. but experiment fails and I do not committed it. However I dont't want to delete this branch, so I tried to go back to master:

git checkout master

and code (controllers, models etc) from the previous experiment was still there in filetree, ApplicationController etc.

I tried git reset --soft <desired-previous-commit-hash> but it not worked.

I assume the second command should return me the state of my app from before creating the branch experiment-branch. Am I right or I do something wrong?

ToTenMilan
  • 582
  • 1
  • 9
  • 19

1 Answers1

1

If you have not tracked the new files you add in the experiment-branch - these are still lying around as untracked files.

Untracked files are not removed when you change branches.

You would need to clean them to remove the untracked files. use git clean -n (dry-run) to identify all the files that are untracked.

Then you could git clean -f to clean all the file shown in the dry-run. Or you could use the interactive mode git clean -I

To revert changes from tracked files, use git checkout .

Refer this post for more details.

Community
  • 1
  • 1
Libin Varghese
  • 1,506
  • 13
  • 19
  • Thank you for answer but that's not what I mean. I have used `git clean -n` & `-f` and all files 100% related to `exp.branch` has gone but code from this branch in files like `application_controller.rb` is still there. What I wanted is to get back to state of the app just before creating this exp.branch like it never happened (with leaving this branch just for review) – ToTenMilan Mar 10 '17 at 10:04