3

This is so problematic, I have just git pull something and then it says there is local change.... I changed nothing... I tried reset hard but it is not useful... Anyone help?

MacBook-Pro$ git reset --hard
HEAD is now at b89fcff the latest code in AWS to identify all difference and keep track
MacBook-Pro$ git checkout dev1.1
error: Your local changes to the following files would be overwritten by checkout:
    OUTPUT_RESULTS_DIR/equity.csv
Please commit your changes or stash them before you switch branches.
Aborting
poke
  • 369,085
  • 72
  • 557
  • 602
Vacassal Alsk
  • 391
  • 1
  • 6
  • 19
  • try `git reset --hard .` where . indicate your current directory. I suspect the equity.csv that lives inside the sub-folder is not getting cleared. – AADProgramming Oct 02 '16 at 19:01
  • *"I have just git pull something and then it says there is local change"* -- a common cause for this behaviour is the presence of mixed newlines (`LF` and `CR LF`) in the same file. Read more here: https://git-scm.com/book/en/v2/Customizing-Git-Git-Configuration#Formatting-and-Whitespace about how to fix it. – axiac Oct 02 '16 at 19:07
  • It is possible that this file is marked as skip-worktree, see http://stackoverflow.com/a/11131211/3906760 – MrTux Oct 02 '16 at 21:48
  • In general, the output of `git status` can really clear up confusions in these siituations. You should always check it yourself, and consider including it in your question too since it gives some additional information about the situation which otherwise has to be guessed. – poke Oct 02 '16 at 21:51

3 Answers3

4

Performing git reset --hard will only affect those files, Git knows about; those that are currently tracked by Git.

When you take the output of git status as a reference, what git reset --hard affects are only those files for which Git has detected modifications which are either staged or not staged. Files listed in the untracked section, and as such are not “known by Git”, are not affected.

So in your case, you have an untracked file OUTPUT_RESULTS_DIR/equity.csv. Doing git reset --hard will not affect it, so it stays where it is. However, the branch dev1.1 you attempt to check out, apparently contains that file. So here, Git will protect you from accidentally losing the content of your local file by preventing you from checking out.

At this point, you could rename the file so that you still have it around but it won’t cause a conflict when checking out the other branch. You could also use git checkout dev1.1 --force to force Git to check out the branch, ignoring any conflicts. However note, that this action cannot be undone, so be careful with it.

poke
  • 369,085
  • 72
  • 557
  • 602
2

If you're certain there are no changes you care about, then there is no reason to try committing or stashing (or even resetting.) You should be able to force the checkout as follows:

git checkout --force dev1.1

The --force option causes Git to discard any local changes rather than failing on them. Just be sure this is really what you want to do.

Chris
  • 451
  • 2
  • 5
-1

Try to stash it maybe will work. :

git stash save
The Javatar
  • 695
  • 5
  • 15