【问题标题】:Restore a shell script file (.sh) in git在 git 中恢复一个 shell 脚本文件 (.sh)
【发布时间】: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 脚本不是很熟悉,所以我不确定这些信息是否会有所帮助。

【问题讨论】:

标签: bash git shell


【解决方案1】:

欢迎来到 Stackoverflow。

看起来您尚未将任何更改推送到“master”(远程)。

所以,你可以这样做:

git reset --hard origin/master

这将撤消您在原始位置(即您的计算机)所做的一切,以匹配您在远程上的上一个“推送”版本(即在您开始任何操作之前)。

祝你好运。

【讨论】:

    猜你喜欢
    • 2015-05-05
    • 2018-08-10
    • 2022-01-09
    • 1970-01-01
    • 1970-01-01
    • 2012-05-22
    • 2019-03-28
    • 2016-07-23
    • 2012-08-15
    相关资源
    最近更新 更多