2015-09-06 61 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