eclipse - 行尾同居终端和 Eclipse Git
问题描述
我们正在处理一个项目并使用 Git 管理我们的代码版本。我们每个功能有一个分支,我们维护的每个版本都有一个分支...问题是,我们使用命令行将项目连接到 git(Eclipse 没有提供足够的功能来正确执行此操作)但通常我们使用 Eclipse 提交, push... 另外有时Eclipse 不想让我们push,我们被迫在命令行中push。
这种情况导致远程上的一些文件以 crlf 行结尾,而另一些文件以 lf 行结尾。所有这些都是由 Eclipse 和终端在 libne 结尾处表现不同引起的,我意识到为时已晚。我现在正在寻找一种简单、正确的方法来使所有文件在 true 时自动 crlf,以及在所有 git 客户端上保证终端和 Eclipse 上相同行为的过程(基于终端上的行为)。
(抱歉英语不好,提前感谢)!
- 编辑 -
我应该准确地说我正在寻找一种解决方案,该解决方案也可以用于转换现有文件,将远程文件转换为远程文件上的 lf 和存储库上的 crlf
解决方案
.gitattributes
您可以尝试使用此条目在存储库中添加和提交文件。
* text eol=crlf
(参考: https ://help.github.com/articles/dealing-with-line-endings/ )
Git 将始终在结帐时将行尾转换为 CRLF。您应该将它用于必须保留 CRLF 结尾的文件,即使在 OSX 或 Linux 上也是如此。
插图:
考虑现有 repo 中有 2 个文件(比如test-repo
),每个文件都有一行。
file_a.txt
file_b.txt
验证文件结尾为\n
.
test-repo (master)$ od -c file_a.txt
0000000 T h i s i s f i l e _ a \n
0000017
test-repo (master)$ od -c file_b.txt
0000000 T h i s i s f i l e _ b \n
0000017
在存储库中添加一个.gitattributes
文件。
test-repo (master)$ vim .gitattributes
添加条目。
* text eol=crlf
提交并推动.gitattributes
。
test-repo (master)$ git add -A
warning: LF will be replaced by CRLF in .gitattributes.
The file will have its original line endings in your working directory.
test-repo (master)$ git commit -m "Adding .gitattributes file"
test-repo (master)$ git push
添加一个新文件,然后在其中键入一行文本。
test-repo (master)$ vim file_c.txt
验证文件结尾为\n
.
test-repo (master)$ od -c file_c.txt
0000000 T h i s i s f i l e _ c \n
0000017
提交并推送添加的文件。
test-repo (master)$ git add file_c.txt
warning: LF will be replaced by CRLF in file_c.txt.
The file will have its original line endings in your working directory.
test-repo (master)$ git commit -m "Added file_c.txt"
test-repo (master)$ git push
将存储库克隆到磁盘上的另一个目录(例如使用 name temp_dir
)。请注意,结尾现在\r \n
代替\n
.
temp_dir/test-repo (master) $ od -c file_a.txt
0000000 T h i s i s f i l e _ a \r \n
0000020
temp_dir/test-repo (master) $ od -c file_b.txt
0000000 T h i s i s f i l e _ b \r \n
0000020
temp_dir/test-repo (master) $ od -c file_c.txt
0000000 T h i s i s f i l e _ c \r \n
0000020
推荐阅读
- python - DisjointSet() 函数
- python - 如何从二进制 .txt 文件创建 .bin 文件?
- plot - Superset 处理时间序列中的缺失值 - 条形图和折线图之间的差异
- angular - 如何使 execCommand 以角度工作
- pine-script - 绘制矩形松树脚本
- r - 如何在 pivot_longer() 中使用 names_pattern() 参数?
- python - 设置 TensorFlow GPU 支持的问题
- java - 如何在android中每5秒在后台无限运行特定方法?
- django - Django没有设置相同的站点cookie
- python-3.x - 如果我有细胞的坐标,如何找到 voronoi 细胞的种子?