[英]Git - Switching branches (windows) & uncommitted changes
I'm having a hard time understanding some git/DCVS concepts. 我很难理解一些git / DCVS概念。 Here's what happened:
这是发生的事情:
git checkout master
git checkout master
切换到我的主分支 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. 我对DCVS的理解是,我可以随意切换分支,即使某个分支的文件比其他分支更多或更少,只要我提交我的文件。 I've tried committing with
git commit -a
and switching to master branch, but I have the same error. 我尝试使用
git commit -a
并切换到master分支,但我有同样的错误。
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; 作为旁注,当我提交git时警告我,LF将被CRLF取代,并警告我一些尾随的空格也是如此; after I commit I do a
git status
and a bunch of files always appear as #modified ...
. 在我提交后,我执行
git status
,一堆文件总是显示为#modified ...
Is this related to git/ windows , or I do not understand correctly what it is supposed to happen? 这与git / windows有关 ,或者我不正确地理解应该发生什么? I just want to switch to my master branch without losing my changes in the other branch.
我只想切换到我的主分支而不会丢失我在其他分支中的更改 。
查找当前分支中未保存的更改时更改分支的git-stash。
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. 但是,听起来git在行结尾时遇到问题,并且它认为所有文件都被修改,即使它们不是。 I don't use git on Windows, but I was going to suggest the "core.autocrlf" option to make the crlf handling work.
我不在Windows上使用git,但我建议使用“core.autocrlf”选项来使crlf处理工作。 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
但是,以下博客条目表明这可能不是一个好主意: http : //weierophinney.net/matthew/archives/191-git-svn-Tip-dont-use-core.autocrlf.html
I solved the problem hacking my pre-commit hook (commenting these lines in .git/hooks/pre-commit
with a #
): 我解决了破解我的预提交钩子的问题(在
.git/hooks/pre-commit
使用#
注释这些行):
# if (/\s$/) {
# bad_line("trailing whitespace", $_);
# }
Just use the following option in .gitconfig file which resides in your users directory. 只需在.gitconfig文件中使用以下选项,该文件位于users目录中。
[core] autocrlf = true [core] autocrlf = true
And it will solve the issue. 它将解决这个问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.