簡體   English   中英

Git不會添加任何文件 - 只是一個空目錄

[英]Git won't add any files - just an empty directory

我一直在Xcode中開發一個iPhone項目,並決定我想把它放在github上。 我在github上創建了一個repo,克隆了它,並將我的所有文件都移到了目錄中。 然后我試圖

git add Directory .

我承諾並推動,發現現在repo中唯一的東西就是這個目錄。 它什么都沒有 - 我甚至無法點擊它在github文件查看器中為repo打開它。 它是文件夾和文件夾名稱的圖片。 我試過了

git add Directory .
git add Directory -A
git commit -a

什么都不會將這些文件添加到目錄中。 我究竟做錯了什么?

可能存在另一個存儲庫。

我的vimfiles中的插件目錄發生在我身上。 再現這樣

  1. git克隆來自GitHub的東西(在我的例子中,一個插件,例如vim-easymotion )到你的存儲庫的某個地方(在我的例子中是vimfiles\\bundle
  2. git add . ,然后git status將顯示所有已實現的是文件夾名稱(在本例中為bundle\\vim-easymotion )已添加為new file
  3. git commit ,然后git push origin master (將更改推送到GitHub)
  4. 在瀏覽器中導航到GitHub以檢查您在步驟1中克隆了某些內容的文件夾,您將看到它將克隆的名稱顯示為空文件

我只是意識到發生了什么,從我在Git Bash的vimfiles\\bundle\\vim-easymotion目錄中,我發出了git config -l ,並注意到對vim-easymotion存儲庫的所有者Lokaltog的引用。 所以我發布了git remote -v ,果然,在該目錄中,Git別名origin https://github.com/Lokaltog/vim-easymotion.git ,這不是我的存儲庫的遠程地址,而是插件的遠程地址。 對我的無知感到震驚,我使用FreeCommander導航到插件目錄,顯示隱藏文件,當然插件創建者的.git文件就在那里。

固化 ,假設你已經克隆別人的倉庫到你的,我做的:

  1. Git Bash在違規的克隆子目錄中, find . | grep /.git | xargs rm -rf find . | grep /.git | xargs rm -rf find . | grep /.git | xargs rm -rf刪除所有不需要的.git文件
  2. git remote -v檢查你是否回到了你自己的遙控器的別名
  3. 現在暫時將整個子目錄移出存儲庫
  4. git status現在將報告文件已被刪除(在我的情況下是vim-easymotion
  5. git add -A進行刪除, git commitgit push origin master從GitHub遠程刪除那個daft文件名
  6. 將(now clean)子目錄移回存儲庫,然后繼續正常運行。
git add .

而在目錄中應該添加所有內容,除非你的.gitignore文件忽略它...

試試git add . 或者使用git gui並通過單擊圖標來選擇其中的文件然后提交它們。

git不跟蹤目錄 - 它跟蹤文件和目錄來獲取。 如果顯式添加文件,則該目錄將作為文件路徑的一部分包含在內。 要添加目錄內容git add Directory/*可以完成這項工作。

聽到git add . ; git commit ,我很驚訝git add . ; git commit git add . ; git commit git add . ; git commit不適合你。 您確定從repo中最頂層的目錄運行這些命令嗎? 以下是您通常期望發生的事情的摘要:

cd ~/Directory  # or whatever the path is in your case
git status      # shows lots of "Untracked files" because this is a new repo
git add .       # adds everything to your index
git status      # now shows lots of "Changes to be committed"
git commit      # fires up the editor and finishes the commit
git show        # shows the commit you just made

在什么時候這會讓你失望?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM