【发布时间】:2020-04-06 13:00:39
【问题描述】:
我正在开发一个包含 shell 脚本文件(比如说a.sh)的项目。
我在 Windows 上克隆了 repo,不小心运行了 a.sh。然后,当我在 git bash 中运行git status 时,我得到了以下信息
git status
on branch master
Changes not staged for commit:
(use "git add <file> ..." to update what will be committed)
(use "git restore <file> ..." to discard changes in working directory)
modified: a.sh
显然,我不希望这个a.sh 被更改,我按照提示使用
git restore a.sh
但是,当我再次运行git status 时,我仍然得到a.sh 被修改的相同信息。
我也分阶段尝试了另一种方式,并使用git commit -am "restore sh" 提交此文件,然后尝试通过git restore head^ a.sh 重置此文件。结果还是一样。
所以我想知道是否有任何方法可以解决这个问题?
仅供参考,据我的同事说,a.sh 用于杀死空闲的 python 线程。当我git diff这个文件时,它表明
old mode 100755
new mode 100644
我对 shell 脚本不是很熟悉,所以我不确定这些信息是否会有所帮助。
【问题讨论】:
-
某些东西似乎在改变 shell 脚本的权限。
-
我从未使用过
git restore。我会使用git checkout a.sh,这是git过去推荐的。 -
@chepner git-scm.com/docs/git-restore 是新的,并替换了
git checkout的一部分 -
这并不完全是重复的,但请参阅stackoverflow.com/q/21691202/1256452