2015-03-25 68 views
2

我有一個新的子目錄中的文件添加到現有的回購...說我有一個回報http://myrepo.git與文件夾work,我必須在文件夾subjectwork下添加新文件。我發現文檔講解如何項目添加到回購:如何在git倉庫中創建新的子文件夾?

cd subject 
git init 
git add . 
git commit 
git remote add origin http://myrepo.git 
git remote -v; git push origin master 

但是,這似乎是專到我的文件添加到myrepo.git,我怎能 myrepo.git/work/subject目錄結構? 謝謝

+0

的「主題」目錄不是空的,我有幾個新文件有 – user270398 2015-03-25 13:28:09

回答

1

你不能添加一個空目錄到git。

一般的解決方法是添加一個空文件.gitkeep,並把它添加到混帳:

touch work/subject/.gitkeep 
git add work/subject/.gitkeep 
git commit -am "Add directory subject" 

這樣一來,該目錄將存在,而且你知道,一旦你在這個其他的可以刪除這個文件目錄。

+0

也許強調添加目錄與添加文件基本相同,只是添加一個空目錄是一個麻煩的特例。 – tripleee 2015-03-25 07:15:57

+1

@tripleee你可以強調任何你想要的,但[這並不是真的](https://git.wiki.kernel.org/index.php/Git_FAQ#Can_I_add_empty_directories.3F)。根本無法添加目錄。 – musiKk 2015-03-25 07:55:21

1

我有一個在新的子目錄添加文件tothe現有回購...

「主題」目錄不是空的,我有幾個新文件有

我認爲你是完全錯誤,不需要創建新的git存儲庫並向其中添加文件。相反,你可以將文件添加到原來的回購本身:

git clone myrepo.git 
cd work 
mkdir subject && cd subject && touch file1 file2 #touch is equivalent to new files added 
git add . && git commit -m "some message" 
git push origin master 

上面應該把你的更改到遠程,並且可以清楚地看到,有在這個過程中創建新的回購協議。

+0

明白了,我的錯誤正是mu所說的:試圖將它作爲新的repo與git init一起添加... – user270398 2015-03-26 12:15:30

+0

@ user270398如果有幫助,不要忘記[接受並且upvote](http://meta.stackexchange .com/questions/5234/how-does-accepting-an-answer-work):) – 2015-04-05 15:23:53

0

得到了它,我的錯誤正是穆說:試圖將其添加爲使用Git初始化新的回購.. 混帳克隆myrepo.git 裁談會工作& &的mkdir主題& & CP myfiles的向受試者& & CP主題 git add。 & & git的承諾-m「一些信息」 混帳推 - 將推動myfiles的進入下工作myrepo.git /主題

相關問題