在git中提交一个“虚拟”文件并制作它

时间:2012-11-28 16:23:06

标签: git virtual

是否可以在git上提交文件系统中不存在的文件?

例如:

git add“hello world”“hello.txt”

我想在文件hello.txt中添加hello world,但我不想在我的文件系统上写hello.txt。

hello.txt不存在,我不希望它存在,除了在git系统上。 (我不想在我的文件系统上写这个文件)。 有没有办法做到这一点?

此致

BUSSIERE

2 个答案:

答案 0 :(得分:4)

是的,你可以这样做。

# write new object to the object database, record its id
obj_id=$(echo hello world | git hash-object --stdin -w)

# add the new file to the index as 'hello.txt'
git update-index --add --cacheinfo 100644 $obj_id hello.txt

# Make a new commit adding the new file
git commit -m "Add new file"

答案 1 :(得分:0)

为什么不在本地创建文件,添加到git,commit并推送到存储库。然后删除本地文件并将其添加到.gitignore,这样它就不会再被拉下来。

虽然我怀疑可能不符合您的要求,但可能需要更多背景