2014-03-19 50 views
8

當我在git中的分支之間切換時,即使沒有更新,我也會看到文件被更改。這最近剛剛開始發生。在git中更改分支導致更改文件

$ git status 
# On branch dev 
nothing to commit (working directory clean) 


$ git checkout master 
Switched to branch 'master' 


$ git status 
# On branch master 
# 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: App.Core/ViewModels/CriteriaViewModel.cs 
#  modified: App.Core/ViewModels/UserManagement/AccountTagsViewModel.cs 
#  modified: App.Core/ViewModels/UserManagement/TagViewModel.cs 
# 
no changes added to commit (use "git add" and/or "git commit -a") 

這些文件,我在Dev分支改變,但加入並提交。任何關於我在做什麼的想法都會導致這種情況?

+0

這特別奇怪,因爲除非您的更改被提交或隱藏,否則您不能切換分支。切換到'master'後沒有任何事情發生? –

+0

@TimCastelijns - 我沒有意識到。 – Joe

+0

你可以關閉VisualStudio,執行''git clean -f -x -d''並重復切換嗎? –

回答

4

您可以檢查這些「更改」文件中的差異是否在eol(行尾)字符中。

如果是,請確保您的core.autocrlf設置爲false:

git config core.autocrlf false 

這將避免在結賬任何自動轉換。

有關更多信息,請參閱「git replacing LF with CRLF」。

如果您需要強制實施一致的eol,請使用.gitattributes指令,如「Fixing the line-endings in a Git repository using the .gitattributes file」中所述。

+1

標記爲答案。它似乎修復了它。謝謝! – Joe