git Git重置具有类型更改状态的文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24533390/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 10:09:57  来源:igfitidea点击:

Git reset files with typechange status

gitsymlink

提问by iphipps

When finding and replacing across a large repository, I get a bunch of files with a typechange status. These are mostly symlinks.

在大型存储库中查找和替换时,我得到一堆具有类型更改状态的文件。这些主要是符号链接。

Rather than

而不是

git checkout -- eachfile.name

Is there a way to reset only typechange files?

有没有办法只重置类型更改文件?

回答by muzz

git status | grep typechange | awk '{print }' | xargs git checkout

回答by zzxyz

Flavor of the existing answer, but I prefer it:

现有答案的味道,但我更喜欢它:

git status --porcelain | awk '{if (=="T") print }' | xargs git checkout

--porcelainis designed for this kind of use.

--porcelain专为这种用途而设计。

Note that this awk answer and the existing answer can be broken with filenames containing spaces, linefeeds, etc in which case we can use.

请注意,这个 awk 答案和现有答案可以用包含空格、换行符等的文件名破坏,在这种情况下我们可以使用。

git status -z | perl -0 -ne 'print  if /^\s*T\s*(.+)$/s' | xargs -0 git checkout

git status -zis the one reallyrecommended for this kind of use and null terminates each entry. perl's -0deals with that ,-neprocesses the given command for each line (or "entry" really). $1refers to the first capture group here, which will include the file name and null terminator.

git status -z真正推荐用于这种用途的,并且 null 终止每个条目。perl-0处理这个问题,-ne为每一行(或真正的“条目”)处理给定的命令。$1指这里的第一个捕获组,它将包括文件名和空终止符。

回答by René H?hle

In most times its better to remove symlinks from your repository. If you work under different operating systems its a problem to have the links in your repository.

在大多数情况下,最好从存储库中删除符号链接。如果您在不同的操作系统下工作,那么在您的存储库中有链接是一个问题。

When you remove it and set it to a new location your file is modified.

当您删除它并将其设置为新位置时,您的文件将被修改。

Some Java Git client have problems with symlinks. They try to follow them and you get an error. I had this problem with the Jenkins client.

某些 Java Git 客户端存在符号链接问题。他们试图跟随他们,你会得到一个错误。我在 Jenkins 客户端上遇到了这个问题。

To add all symlinks to the .gitignoreyou can run the following command under Linux

要将所有符号链接添加到.gitignore您可以在 Linux 下运行以下命令

find /your/directory -type l >> .gitignore

find /your/directory -type l >> .gitignore