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?

8
  • That seems to be an issue with line-endings. A similar issue has already been discussed here. Commented Nov 20, 2015 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. Commented Nov 20, 2015 at 11:57
  • Try git stash before checkout. Commented Nov 20, 2015 at 11:59
  • Yes, so what does git diffsay? Maybe you saved accidently and changed line-endings on windows!? Commented Nov 20, 2015 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? Commented Nov 20, 2015 at 12:18

2 Answers 2

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.

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

3 Comments

doing the rm test.txt followed by the checkout -- test.txt does not help, same problem
Try git rm instead of rm
rm deletes a file. And trying to checkout does not makes sense error: pathspec '/src/test/resources/blob.txt' did not match any file(s) known to git
0

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

Comments

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.