0

I have two branches below:

 $ git branch
      master
    * mvn

mvn branch had a modified file when i did git checkout master and then git reset --hard HEAD^ it also did the same op for the mvn branch, meaning my modified file was gone .

what can i do so that the ops in master branch do not affect mvn branch or vice versa?

ealeon
  • 12,074
  • 24
  • 92
  • 173
  • 2
    Did you commit your changes to `mvn` before switching to `master`? – 0x5453 Oct 07 '19 at 17:12
  • @0x5453 they are left as modified – ealeon Oct 07 '19 at 17:13
  • [related](https://stackoverflow.com/a/25791647/2550406) – lucidbrot Oct 07 '19 at 17:13
  • What do you mean by "mvn branch had a modified file"? Do you mean that you had a file that was modified in the working directory and the mvn branch was checked out? Then, when you checked out 'master', you had a modified file in the working directory. Then you did reset --hard and you no longer had a modified file in the working directory. – William Pursell Oct 07 '19 at 17:20

1 Answers1

1

Possible things can be done

  1. Whenever someone needs to go another branch, he/she should commit the current changes. If this is not the in commit stage yet then a dummy commit can also be an option.Later dummy commit can be updated in a meaningfull one through git ammed.
  2. If one don't want to keep the changes or wants to put this changes in another branch then he/she should stash the current changes and pop the stash in targeted branch.
Shakil
  • 4,520
  • 3
  • 26
  • 36
  • oh so branches are commits only? if if it has changes not committed then chaning branches will not be isolated to that branch? – ealeon Oct 07 '19 at 17:16