2

I renamed a folder and it is no longer tracked by git. I checked the remote repo that I push to and oddly the folder with the new name is there but there are no contents.

I checked my .gitignore just out of diligence, and there is nothing that says to ignore the contents of this folder.

I changed it from web1 to web-domain to be more descriptive.

I use this script to push

// pushes to am-godaddy
p-am-godaddy() {
  git add -A .
  git commit -m $a
  git push am-godaddy master
}
Holger Just
  • 52,918
  • 14
  • 115
  • 123
cade galt
  • 3,843
  • 8
  • 32
  • 48
  • 2
    Did you use `git mv` to do the rename? – Carl Norum Sep 06 '15 at 17:10
  • ...most probably no. Checkout the [answers to this question](http://stackoverflow.com/q/2641146/319204) that showcase the proper method to rename/move directories and properly track them i.e. maintain their history within a git repository. – TheCodeArtist Sep 06 '15 at 17:13
  • 2
    "the folder with the new name is there but there are no contents" This seems unlikely; Git doesn't track empty directories at all. Why did you write a shell function to push your code? IMO it adds an unnecessary layer of complexity. *Edit: It looks like you're adding, committing, and pushing all at once. I really don't understand why you would do this.* – ChrisGPT was on strike Sep 06 '15 at 17:13
  • 1
    @CarlNorum, TheCodeArtist, `git mv` is no different from `git rm` and then `git add`. Git doesn't track renames; it detects them after the fact based on similarity of content. – ChrisGPT was on strike Sep 06 '15 at 17:15

2 Answers2

2

Your use of git add -A . will cover this case. I ran through a simulation of what you're experiencing. Renaming an empty folder will be ignored and folder name changes (with content) will show a delete and untracked, until you run the next git add -A . where it changes to a rename event:

➜  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
mbb
  • 3,052
  • 1
  • 27
  • 28
0

When working with a folder hierarchy always use git commands instead of the normal bash commands.

That is use git mv instead of mv.

If you didn't do this, Git will produce un-expected behavior. And of course remember that Git tracks files not folders.