Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git - Switching branches (windows) & uncommitted changes

Tags:

git

windows

dvcs

I'm having a hard time understanding some git/DCVS concepts. Here's what happened:

  1. I created a git project, and imported it from an SVN repo
  2. I made some commits
  3. I wanted to experiment something, so I created a branch called constants-update
  4. I switched to constants-updatebranch, moved some files, deleted others and added many more
  5. I committed to this branch
  6. Now I'm trying to switch to my master branch using git checkout master
  7. I got this error: error: You have local changes to 'src/groovy/Constants.groovy'; cannot switch branches.

My understanding of DCVS is that I can switch branches at will, even if some branch has more or less files than the others, as long as I commit my files. I've tried committing with git commit -a and switching to master branch, but I have the same error.

As a side note, when I commit git warns me that LF will be replaced by CRLF and warns me about some trailing whitespaces also; after I commit I do a git status and a bunch of files always appear as #modified ....

Is this related to git/windows, or I do not understand correctly what it is supposed to happen? I just want to switch to my master branch without losing my changes in the other branch.

like image 996
Miguel Ping Avatar asked Nov 03 '08 02:11

Miguel Ping


3 Answers

Lookup git-stash for changing branches while there are unsaved changes in the current branch.

like image 175
Grant Limberg Avatar answered Oct 25 '22 19:10

Grant Limberg


You are correct in your thinking about how this should work.

However, it sounds like git is having issues with the line endings, and it thinks all your files are modified even when they aren't. I don't use git on Windows, but I was going to suggest the "core.autocrlf" option to make the crlf handling work. However, the following blog entry indicates that this might not be a good idea: http://weierophinney.net/matthew/archives/191-git-svn-Tip-dont-use-core.autocrlf.html

like image 42
Greg Hewgill Avatar answered Oct 25 '22 20:10

Greg Hewgill


I solved the problem hacking my pre-commit hook (commenting these lines in .git/hooks/pre-commit with a #):

#       if (/\s$/) {
#       bad_line("trailing whitespace", $_);
#       }
like image 26
Miguel Ping Avatar answered Oct 25 '22 19:10

Miguel Ping