2

I have cloned a repository on windows 8 and I have not modified any files. When I do a git status I get the following though:

$ git st
On branch myFeature
Your branch is up-to-date with 'origin/myFeature'.

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

        modified:   test.txt

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

Now I want to checkout master but I am not allowed to do that:

$ git co master
error: Your local changes to the following files would be overwritten by checkout:
        test.txt
Please, commit your changes or stash them before you can switch branches.
Aborting

I have then tried:

git reset --hard
git clean -f
git checkout master

same error.

git checkout -- test.txt
git clean -f
git checkout master

same error.

So I still get the above error when I try to checkout master - and the test.txt file is still marked as being modified.

Below is the output from git config -l (where I have removed some private entries)

$ git config -l
core.symlinks=false
core.autocrlf=false
color.diff=auto
color.status=auto
color.branch=auto
color.interactive=true
pack.packsizelimit=2g
help.format=html
http.sslcainfo=/bin/curl-ca-bundle.crt
sendemail.smtpserver=/bin/msmtp.exe
diff.astextplain.textconv=astextplain
rebase.autosquash=true
core.autocrlf=false
core.editor="C:/Program Files (x86)/GitExtensions/GitExtensions.exe" fileeditor
core.longpaths=true
core.packedgitlimit=128m
core.packedgitwindowsize=128m
core.hidedotfiles=false
alias.st=status
alias.co=checkout
merge.tool=kdiff3
diff.guitool=kdiff3
mergetool.kdiff3.path=C:/Program Files/KDiff3/kdiff3.exe
difftool.kdiff3.path=C:/Program Files/KDiff3/kdiff3.exe
push.default=simple
pack.deltacachesize=128m
pack.packsizelimit=128m
pack.windowmemory=128m
color.branch.upstream=cyan
core.repositoryformatversion=0
core.filemode=false
core.bare=false
core.logallrefupdates=true
core.symlinks=false
core.ignorecase=true
core.hidedotfiles=false
core.autocrlf=false
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*

Any ideas on how to reset my repository?

u123
  • 15,603
  • 58
  • 186
  • 303
  • Try `git stash` before `checkout`. – Ôrel Nov 20 '15 at 11:59
  • That seems to be an issue with line-endings. A similar issue has already been discussed [here](http://stackoverflow.com/questions/2016404/git-status-shows-modifications-git-checkout-file-doesnt-remove-them). – SevenEleven Nov 20 '15 at 11:45
  • Nope that does not have any effect. I did try that but git clean only works on untracked content which is not the case for the test.txt file. – u123 Nov 20 '15 at 11:57
  • Yes, so what does `git diff`say? Maybe you saved accidently and changed line-endings on windows!? – SevenEleven Nov 20 '15 at 12:06
  • Yes git diff shows that all lines have been removed and then added again indicates a line ending change. But is it not possible to reset that? – u123 Nov 20 '15 at 12:18
  • Then, I guess, it is an issue with `autocrlf`. What happens if you set do `git config --global core.autocrlf false` – SevenEleven Nov 20 '15 at 12:23
  • core.autocrlf=false, see output from in original post for git config -l – u123 Nov 20 '15 at 12:27
  • Did you set autocrlf to false before or after cloning the repo? If you changed it _after_ cloning the repo, just delete and try cloning it again. – codemonkey Nov 20 '15 at 13:44

2 Answers2

0

First ensure test.txt is not in .gitignore (i.e. you have not added it).

Then do

git rm test.txt
git checkout -- test.txt

Add a -f if you like

The rm will get around any line ending changes

Finally you can

git reset --hard
git checkout master

etc.

abligh
  • 24,573
  • 4
  • 47
  • 84
0

just use git checkout --filename or git checkout -- . to discard all changes in modified files

Tequila
  • 726
  • 7
  • 23