我想修改一个(文本)文件的索引,而不必更改工作树文件状态。 这可能吗?
git reset path/to/file
然后提取其完整补丁
git diff path/to/file > /path/to/tmpfile
git apply --cached /path/to/tmpfile
请参见:
git help apply
git show HEAD:path/to/your/file.txt > /some/other/place/file.txt
# modify the file in /some/other/place/file.txt
git --work-tree=/some/other/place add /some/other/place/file.txt
是的,您可以使用git update-index
在特定路径上明确地暂存一个blob。
git update-index --cacheinfo 100644 <sha1-of-blob> path/in/repo
如果路径是一个全新的文件,您还需要使用--add
。
如果要暂存的文件是一个在Git仓库中不存在的blob,则可以使用git hash-object
将新的blob存储在Git仓库中,例如:
blobid=$(command_that_creates_output | git hash-object -w --stdin)
或者
blobid=$(git hash-object -w /path/not/necessarily/in/repository)
然后,您可以像上面那样对 Blob 进行分段。
git update-index --cacheinfo 100644 blobid path/in/repo
--work-tree
选项的 Git 命令到底是做什么的?需要哪个版本的 Git?提供的路径是否总是添加文件的父目录? - Motpwd
打印并由cd
修改的内容。在这种情况下,你指的是什么? - Laurence Gonsalves