2015-09-06 62 views
2

我重命名了一個文件夾,它不再被git跟蹤。我檢查了我推送到的遠程回購,奇怪的是具有新名稱的文件夾在那裏,但沒有內容。重新命名文件夾由Git跟蹤?

我檢查了我的.gitignore只是出於勤奮,沒有什麼說可以忽略此文件夾的內容。

我將其從web1更改爲web-domain以更具描述性。

我使用這個腳本推

// pushes to am-godaddy 
p-am-godaddy() { 
    git add -A . 
    git commit -m $a 
    git push am-godaddy master 
} 
+2

你用'git mv'來做重命名嗎? –

+0

...最有可能沒有。檢出[這個問題的答案](http://stackoverflow.com/q/2641146/319204),其中展示了重命名/移動目錄並正確跟蹤它們的正確方法,即在git存儲庫中維護它們的歷史記錄。 – TheCodeArtist

+2

「新名稱的文件夾在那裏,但沒有內容」這似乎不太可能; Git根本不跟蹤空目錄。你爲什麼寫一個shell函數來推送你的代碼?海事組織增加了一層不必要的複雜性。 *編輯:它看起來像你一次添加,提交和推送。我真的不明白你爲什麼要這麼做。* – Chris

回答

0

當用文件夾層次工作始終使用git命令而不是正常的bash命令

這就是使用git mv而不是mv

如果你沒有這樣做,Git會產生不期望的行爲。當然要記住,Git跟蹤文件而不是文件夾。

2

您使用的git add -A .將覆蓋這種情況。我仿效了你正在經歷的一切。重命名一個空文件夾都將被忽略和文件夾名稱的變化(與內容),將顯示一個delete和未跟蹤,直到你下次運行git add -A .它變成一個重新命名事件:

➜ playing git:(master) ls -lah 
total 72 
drwxr-xr-x 16 basho staff 544B Jun 12 16:27 . 
drwxr-xr-x 17 basho staff 578B Sep 3 03:44 .. 
drwxr-xr-x 14 basho staff 476B Sep 6 13:16 .git 
-rw-r--r-- 1 basho staff 68B Dec 25 2014 README.md 
-rw-r--r-- 1 basho staff 4.5K Dec 25 2014 Vagrantfile 
-rw-r--r-- 1 basho staff  0B Dec 25 2014 another 
-rw-r--r-- 1 basho staff  0B Dec 25 2014 bob 
-rw-r--r-- 1 basho staff 1.3K Jun 12 16:27 columns.md 
-rw-r--r-- 1 basho staff  0B Dec 25 2014 file 
-rw-r--r-- 1 basho staff  8B Dec 25 2014 junk 
-rw-r--r-- 1 basho staff 60B Jan 1 2015 markdowntest.md 
-rw-r--r-- 1 basho staff 141B Jan 17 2015 test.rb 
-rw-r--r-- 1 basho staff 39B Dec 25 2014 vmware.stuff 
-rw-r--r-- 1 basho staff 113B Dec 25 2014 vmware.stuff.orig 
-rw-r--r-- 1 basho staff  0B Dec 25 2014 will-this-work 
-rw-r--r-- 1 basho staff  0B Jan 1 2015 working 
➜ playing git:(master) mkdir test 
➜ playing git:(master) git status 
On branch master 
Your branch is up-to-date with 'origin/master'. 
nothing to commit, working directory clean 
➜ playing git:(master) ls 
README.md   another   columns.md  junk    test    vmware.stuff  will-this-work 
Vagrantfile  bob    file    markdowntest.md test.rb   vmware.stuff.orig working 
➜ playing git:(master) touch test/file-in-test 
➜ playing git:(master) ✗ ls 
README.md   another   columns.md  junk    test    vmware.stuff  will-this-work 
Vagrantfile  bob    file    markdowntest.md test.rb   vmware.stuff.orig working 
➜ playing git:(master) ✗ git status 
On branch master 
Your branch is up-to-date with 'origin/master'. 
Untracked files: 
    (use "git add <file>..." to include in what will be committed) 

    test/ 

nothing added to commit but untracked files present (use "git add" to track) 
➜ playing git:(master) ✗ git add . 
➜ playing git:(master) ✗ git commit -m "adding folder with stuff in it" 
[master 06996f3] adding folder with stuff in it 
1 file changed, 0 insertions(+), 0 deletions(-) 
create mode 100644 test/file-in-test 
➜ playing git:(master) git status 
On branch master 
Your branch is ahead of 'origin/master' by 1 commit. 
    (use "git push" to publish your local commits) 
nothing to commit, working directory clean 
➜ playing git:(master) mv test/ other 
➜ playing git:(master) ✗ ls 
README.md   another   columns.md  junk    other    vmware.stuff  will-this-work 
Vagrantfile  bob    file    markdowntest.md test.rb   vmware.stuff.orig working 
➜ playing git:(master) ✗ git status 
On branch master 
Your branch is ahead of 'origin/master' by 1 commit. 
    (use "git push" to publish your local commits) 
Changes not staged for commit: 
    (use "git add/rm <file>..." to update what will be committed) 
    (use "git checkout -- <file>..." to discard changes in working directory) 

    deleted: test/file-in-test 

Untracked files: 
    (use "git add <file>..." to include in what will be committed) 

    other/ 

no changes added to commit (use "git add" and/or "git commit -a") 
➜ playing git:(master) ✗ git add -A . 
➜ playing git:(master) ✗ git status 
On branch master 
Your branch is ahead of 'origin/master' by 1 commit. 
    (use "git push" to publish your local commits) 
Changes to be committed: 
    (use "git reset HEAD <file>..." to unstage) 

    renamed: test/file-in-test -> other/file-in-test