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
4
  • try git reset --hard . where . indicate your current directory. I suspect the equity.csv that lives inside the sub-folder is not getting cleared. Commented Oct 2, 2016 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: git-scm.com/book/en/v2/… about how to fix it. Commented Oct 2, 2016 at 19:07
  • It is possible that this file is marked as skip-worktree, see stackoverflow.com/a/11131211/3906760 Commented Oct 2, 2016 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. Commented Oct 2, 2016 at 21:51

3 Answers 3

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.

Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

-1

Try to stash it maybe will work. :

git stash save

1 Comment

If git reset --hard did not clear it, it also won’t be included in a stash.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.