0

I made a mistake moving between branches.

git checkout -f myBranch

This is my mistake and lost my data. is possible to revert or reset or rollback like undo to restore my files?

Thanks!!

Zoe
  • 27,060
  • 21
  • 118
  • 148
Fabio
  • 1,913
  • 5
  • 29
  • 53
  • Possible duplicate of [How to revert Git repository to a previous commit?](http://stackoverflow.com/questions/4114095/how-to-revert-git-repository-to-a-previous-commit) – dkaz Feb 23 '17 at 22:48
  • not clear wht you are saying. you mean you lost uncommitted changes when you try to switch branches?? Normally when you have uncommited changes, git won't allow you try to switch branches. – Supun Wijerathne Feb 24 '17 at 04:55

1 Answers1

1

If you check out an other branch using checkout -f, your uncommited changes are lost (except for untracked files). As said here :

-f --force

When switching branches, proceed even if the index or the working tree differs from HEAD. This is used to throw away local changes.

If your changes were local and never even part of a commit, there is no way to restore them, since git does not know about them.

Any operation using -f or --force should be used with caution, since yout can potentially loose your local changes with no way to recover them. Make sure you have a clean working tree (e.g. commited local changes) before performing such operations.

I assume you lost your local changes here, or do you speak of changes that already were commited at any point?

kowsky
  • 12,647
  • 2
  • 28
  • 41