1

This sound basic question and duplicate of Remove local Git changes most likely. However, I did try many option but could not get a clean slate. I am heading to create a new branch but I get error:

> error: Your local changes to the following files would be overwritten
> by checkout:
>        js/us-states.xml 
> Please, commit your changes or stash them before you can switch branches. Aborting

Since I have not modified this file (it got automatically modified) I need to discard the changes. Seems like it shown modified due to LF-CRLF conversion. I am on Windows machine.

I tried:

  1. git checkout .
  2. git clean -f
  3. git reset --hard
  4. git stash -u
  5. git gui > Revert changes

But no matter what command I run, as soon as I run git status it show me this output:

D:\GitHub\Project>git status On branch master Your branch is up-to-date with 'origin/master'.

Changes not staged for commit: (use "git add ..." to update what will be committed) (use "git checkout -- ..." to discard changes in working directory)

    modified:   js/us-states.xml

no changes added to commit (use "git add" and/or "git commit -a")

I am getting into such issues frequently now a days. One or the other way I solve it but like to know what's going on and is there a permanent solution for this issue.

Why it does not let me discard the changes for this file?

Update 1:

As a work around, I committed the change (not pushed) to get a clean slate as desired when I run git status. I was able to switch to another branch. Later I ran

git reset --hard origin/master

this in effect, removed temp local commit.

Community
  • 1
  • 1
SBirthare
  • 5,117
  • 4
  • 34
  • 59

0 Answers0