【问题标题】:On git line-endings again再次在 git 行尾
【发布时间】:2015-05-08 03:56:01
【问题描述】:

我们所有的开发人员都在 Windows 机器上工作,并在 Linux 上完成构建。

为了符合真正的方式,我们决定规范化行尾并遵循场景described on GitHub

后来发现,从一个分支切换到另一个分支时,有时会出现一些文件被标记为已更改而没有检测到内容更改的情况。

然后我遇到了GitBook documentation 行尾及其规范化。

所以我想知道这两种方法有什么区别?

git rm --cached -r .
# Remove everything from the index.

git reset --hard
# Write both the index and working directory from git's database.

git add .
# Prepare to make a commit by staging all the files that will get normalized.
# This is your chance to inspect which files were never normalized. You should
# get lots of messages like: "warning: CRLF will be replaced by LF in file."

git commit -m "Normalize line endings"
# Commit

$ rm .git/index     # Remove the index to force git to
$ git reset         # re-scan the working directory
$ git status        # Show files that will be normalized
$ git add -u
$ git add .gitattributes
$ git commit -m "Introduce end-of-line normalization"

因为这两个在git status 中给出了不同的文件集。

我应该什么时候将标准化文件推送到远程?

UPD:这是我在运行 git 命令和在分支之间切换时遇到的一种情况:

>git status
on develop, no changes

>git checkout -t origin/BRANCH-1 && git status
Branch BRANCH-1 set up to track remote branch GPIII-96 from origin.
Switched to a new branch 'BRANCH-1'
modified: A.java
modified: B.java
modified: C.java

>file A.java
A.java: ASCII text, with CRLF line terminators

>git rm --cached -r . && git reset --hard && git status
# On branch BRANCH-1
nothing to commit (working directory clean)

*WTF??*

>git checkout develop -f && git status
modified: D.java

*WTF???*

>git checkout BRANCH-1 -f && git status
modified: A.java
modified: B.java
modified: C.java

*WTF???*

【问题讨论】:

    标签: git line-endings


    【解决方案1】:

    我曾经遇到过同样的问题。我只能给你一个建议。

    对我来说,管理我们的行尾不是 VCS 的工作。它是开发人员或 IDE 的工作。因此,将您的行尾标准化一次,然后将 Windows 机器 IDE 上的行尾切换为 Unix-Line-Endings 并再次感到高兴。这就是解决我们的问题的方法。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-08-19
      • 2020-08-14
      • 1970-01-01
      • 1970-01-01
      • 2019-08-20
      • 2019-07-05
      • 2018-05-08
      • 2016-04-09
      相关资源
      最近更新 更多