我愿意
第 1 步)在分支 A 和 B 之间进行 Git 差异,
第2步)选择一组更改(选择这些更改,其中文件权限从模式100755更改为模式100644),
步骤 3) 将那些选定的更改重置到分支 A(或从分支 B 中挑选更改)。
我该如何使用 git?
部分解决方案:
第 1 步和第 2 步)我能够列出这些文件,其中包含
git diff --仅名称“A”“B”| grep '模式更改 100755 => 100644'
第 3 步)如何将选定的文件模式更改重置到分支 A(或从分支 B 中挑选更改)? 我只想将步骤 1 中选择的文件的文件状态恢复到分支 A 中的状态。
注意:我有几千个文件,所以逐个挑选不是解决方案。
@jthill:不幸的是,在 MINGW64 (Windows) 上执行 chmod 时没有效果,可能是因为 Windows。
$ ls -la admin/langdoc.php
-rw-r--r-- 1 klor 197121 9844 Apr 25 23:04 admin/langdoc.php
$ chmod 755 admin/langdoc.php
$ ls -la admin/langdoc.php
-rw-r--r-- 1 klor 197121 9844 Apr 25 23:04 admin/langdoc.php
因为我在 Windows 中进行开发,并且存储库存储在 Linux 中,所以基于 chmod 的权限更改不是我的方式,因为 Windows 不支持类似 Linux 的 755 或 644 权限。
@jthill 然而给了我一个良好的开端,让我有一个可行的解决方案。谢谢!
我找到了一种改进的方法,它也适用于 Windows 和 Linux,基于 @jthill 的回答:
使用
在 git 内部更改权限/模式git update-index --chmod=+x file.php
解决方案
<强>1。文件模式更改:模式更改 100755 => 100644
```
# 1st line just creates a file to be able to check if mode of same files are changing
git diff --raw "A" "B" | sed -n '/^:100755 100644/ s/[^\t]*.//p' > diff_mode_100755.txt
# 2nd is doing the mode change from 100755 to 100644
git diff --raw "A" "B" | sed -n '/^:100755 100644/ s/[^\t]*.//p' | xargs -d\\n git update-index --chmod=+x
git commit -m "Restore original 755 file mode"
```
<强>2。文件模式更改:模式更改 100644 => 100755
```
# 1st line just creates a file to be able to check if mode of same files are changing
git diff --raw "A" "B" | sed -n '/^:100644 100755/ s/[^\t]*.//p' > diff_mode_100644.txt
# 2nd is doing the mode change from 100644 to 100755
git diff --raw "A" "B" | sed -n '/^:100644 100755/ s/[^\t]*.//p' | xargs -d\\n git update-index --chmod=-x
git commit -m "Restore original 644 file mode"
```
最佳答案
git diff --raw A B | sed -n '/^:100755 100644/ s/[^\t]*.//p'
将列出您想要选择的路径,对其进行编辑,然后使用 a-x 或 a+x 将其通过管道传输到 xargs -d\\n chmod
,具体取决于您是否在 A 上并且想要丢失了 B 上的 x 位或想要恢复它。
在 Windows 上,可执行位毫无意义,您可以直接更新索引条目,而不是 chmod a+x
文件然后让 git add 更新索引,git update -index --chmod=+x
文件设置索引中的位,-x
清除它。
关于分支 A 和 B 之间的 Git diff,选择一组文件模式更改,将这些更改重置到分支 A,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43615855/