GIT不断在结账时引入未经注册的变更

时间:2017-11-10 15:23:56

标签: git

我在BitBucket Server中创建了一个新的存储库,它已经填充并正在使用中。但是,我们的一些用户(包括我自己)遇到了结帐时出现意外更改的问题。它不会出现在每次结账时,只会偶尔出现。

这些更改似乎是对相关文件的完全重写。例如,git diff没有显示所有行结尾都已更改。我们还使用SVN Mirror从trunk上的旧版subversion存储库中引入更改 - >主。 每个人都在Windows上使用2.14版本的git。

以下命令会暂时修复它,但它不可避免地会回来

git rm --cache -r
git reset --hard

示例:

MINGW64 /c/code/git/repo (master)
$ git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
  (use "git push" to publish your local commits)

nothing to commit, working tree clean

MINGW64 /c/code/git/repo (master)
$ git checkout -
Switched to branch 'dev/test_branch'

MINGW64 /c/code/git/repo (dev/test_branch)
$ git status
On branch dev/test_branch
nothing to commit, working tree clean

MINGW64 /c/code/git/repo (dev/test_branch)
$ git checkout -
Switched to branch 'master'
Your branch is ahead of 'origin/master' by 1 commit.
  (use "git push" to publish your local commits)

MINGW64 /c/code/git/repo (master)
$ git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
  (use "git push" to publish your local commits)

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:   <snip-filename>.java
        modified:   <snip-filename2>.java
 ... etc ...
        modified:   <snip-lastfilename>.java

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

编辑:检查git diff -w以排除空格更改显示没有差异,因此它肯定与eol相关。

1 个答案:

答案 0 :(得分:1)

对于这个问题,它最终归因于Subversion镜像。启用后,来自Subversion的行结尾不会自动更正,原来的eol也是如此。通过.gitattributes或通过用户的默认设置设置GIT存储库,以自动纠正行结尾,这将导致原始行结束为CRLF的不匹配,而更新版本仅为LF。

这是通过使用

确定的
git diff --ignore-space-at-eol

与之前的版本没有任何差异。

解决方案是提交并将行结束调整后的文件推送到GIT中。然后镜像到Subversion,并再次将它们重新同步。

有关详细信息,我在此处找到了一个非常有用的指南:https://help.github.com/articles/dealing-with-line-endings/