Rest git 在推送到远程源之前更改文件?

Rest git changes files before push to remote origin?

我想在推送到远程源之前重置特定文件的更改,并且在成功推送之后所有更改都返回到文件,而且我不想使用 .gitignore 因为我需要这些文件被 git

跟踪

好的,所以你正在做一些尚未完成的更改,
但你也想提交那个回购协议。

git stash comes to rescue you.

有关详细信息,请查看 https://git-scm.com/docs/git-stash

您可能希望暂时 'ignore' 更改工作目录中的这些文件,方法是:

git update-index

--[no-]assume-unchanged

When this flag is specified, the object names recorded for the paths are not updated. Instead, this option sets/unsets the "assume unchanged" bit for the paths. When the "assume unchanged" bit is on, the user promises not to change the file and allows Git to assume that the working tree file matches what is recorded in the index. If you want to change the working tree file, you need to unset the bit to tell Git. This is sometimes helpful when working with a big project on a filesystem that has very slow lstat(2) system call (e.g. cifs).

Git will fail (gracefully) in case it needs to modify this file in the index e.g. when merging in a commit; thus, in case the assumed-untracked file is changed upstream, you will need to handle the situation manually.

git-update-index --no-assume-unchanged

git update-index --assume-unchanged file.txt
git update-index --no-assume-unchanged file.txt
git ls-files -v