2

Like an idiot, I made changes out of scope of my current branch.

I changed 5 files

 M  app/form_models/car_registration/basics.rb
M   app/form_models/car_registration/horse.rb
M   app/views/car_registration/basics.rb
M   app/views/car_registration/horse.html.erb
M   spec/factories/car.rb
M   spec/form_models/car_registration/basic_spec.rb

I would like to commit my basics.rb files to my branch, basics, and my horse.rb files to a new branch, horse. I already did git checkout -b horse, and all the files displayed. I have not committed yet. What do I do?

user2012677
  • 5,465
  • 6
  • 51
  • 113

1 Answers1

3

you should add the files you want to commit

git add basics.rb

and then commit

git commit -m "your message"

then stash changes

git stash

change branch

git checkout -b new_branch

Unstash changes

git stash pop

and commit all changes in your new branch

git commit -am "commit message".

Cheers

Pablo Martinez
  • 449
  • 2
  • 6
  • I think it worked, but I also changed the name of the branch at the end and now getting fatal: feat/mvc/car-registration/horse cannot be resolved to branch. when I do git push --set-upstream origin feat/mvc/car_registration/horse – user2012677 Mar 08 '19 at 21:06
  • 1
    https://stackoverflow.com/questions/38034866/cant-push-to-remote-branch-cannot-be-resolved-to-branch – Pablo Martinez Mar 08 '19 at 21:08
  • Good answer, but the stash steps aren't necessary here. After the first commit, create the new branch as you did, then just add and commit again. – Romain Valeri Mar 09 '19 at 15:05