2012-11-28 36 views
1

這可能會提交git上文件系統上不存在的文件嗎?在git中提交一個「虛擬」文件並使之成爲

例:

混帳添加 「Hello World」 的 「hello.txt的」

我想在文件hello.txt的添加你好世界,但我不想寫hello.txt的我文件系統。

hello.txt不存在,我不希望它存在,除非在git系統上。 (我不想在我的文件系統上寫這個文件)。 有沒有辦法做到這一點?

問候

BUSSIERE

+0

爲什麼要這麼做? – Philipp

+0

這可能是一個非常糟糕的主意。爲什麼不想在文件系統上創建文件的任何好理由? – Chronial

+0

我認爲這與'git filter-branch --index-filter'調用結合使用很有用。 – MvG

回答

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" 
+0

你能解釋我100644嗎?這似乎是這個解決方案,謝謝。 – user462794

+1

這是不可執行的常規文件的模式參數。 'git help update-index' –

0

你爲什麼不創建本地文件,添加到Git的,提交和推到倉庫。然後刪除本地文件並將其添加到.gitignore,以便它不會再次被拉下。

雖然我懷疑可能不符合您的要求,可能需要更多的上下文

+0

我想添加論壇帖子作爲git中的文件(帶觸發器),每次創建新帖子時,我都想將它作爲文件添加到git中。謝謝 – user462794

相關問題