user285594
user285594

Reputation:

How to use Git for updating my directory and other contents?

I have a directory like below:

/var/tmp/main
.. plugin1
.... mysource.c
.. plugin2
.... mysource.c
.. plugin3
.... mysource.c

And I created a repository. After that, I applied the below:

$ cd /var/tmp/main
$ git init
$ echo "hello git plz work" >> README
$ git add README
$ git commit -m 'first commit works'
$ git remote add origin git@...../main.git

$ git push origin master

I also tried

$ git add .
$ git status
# On branch master
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#   (commit or discard the untracked or modified content in submodules)
#
#   modified:   folder1 (modified content)
#   modified:   folder2 (modified content)
#   modified:   folder3 (modified content)
#   modified:   folder4 (modified content)
#   modified:   folder5 (modified content)
#   modified:   folder6 (modified content, untracked content)
#   modified:   folder7 (modified content)
#   modified:   library (modified content, untracked content)
#
no changes added to commit (use "git add" and/or "git commit -a")

$ git commit -m 'Suggested by Stack experts'
$ git push

Tried also .gitignore

$ cat .gitignore 
*.[oa]
*.pyc
*.gcda
*.gcno
*.la
*.lo
*.loT
*.sw[po]
*.tar.*
*~
.deps
.libs
ABOUT-NLS
INSTALL
Makefile
Makefile.in
aclocal.m4
autom4te.cache
autoregen.sh
compile
config.guess
config.h
config.h.in
config.log
config.rpath
config.status
config.sub
configure
depcomp
install-sh
libtool
ltmain.sh
missing
stamp-h1

Same so far...

All set but after 14 hours I still do not see all of my directories in Git, I only see the README file showing.

How can I commit all? (following http://scottr.org/presentations/git-in-5-minutes/ )

Upvotes: 0

Views: 385

Answers (3)

Kzqai
Kzqai

Reputation: 23082

Here is the simple method to add empty directories:

//create some empty, gitignore files.
touch ./someDir/.gitignore
touch ./someOtherDir/.gitignore

...etc..

git add ./someDir/.gitignore
git add ./someOtherDir/.gitignore

...etc...

git commit -am "  Add empty project directories."

This is because, as mentioned in other answers git tracks files in directories, but ignores directories on their own. This also might be fixed/solved in the git add mechanism in more up to date versions (I vaguely remember them adding their own .gitignore files to empty directories), so I'd really recommend trying to upgrade to the highest git version you can for that and other benefites, your distro may provide by default an older version, as ubuntu and debian do.

Edit:

The above technique is designed for the minimal amount of disturbance of your working directories in order to get empty folders tracked. -Each- directory would in my examples get their own .gitignore file (you can have as many .gitignore files as you like, they are additive).

So at the end your folder structure would look like this:

/var/tmp/main
.. plugin1
.... mysource.c
.... .gitignore
.. plugin2
.... mysource.c
.... .gitignore
.. plugin3
.... mysource.c
.... .gitignore

And then you would add the .gitignore files as placeholders!

But let's take a step back and try the opposite tactic:

Maximum visibility.

Go to any folder you want to add, e.g. plugin1 . Create a file in that folder, call it placeholder.

Now navigate to that folder from the command line, e.g. cd /var/tmp/main/plugin1/ and git add that placeholder file, e.g. git add placeholder . You've told git that you want that file tracked (if you type git diff you can review the "proposed" changes. It'll tell you that it sees the file, but that it's just an empty file, which is fine).

Now commit the file: git commit placeholder -m " Adding a Placeholder file."

When you add any file, all the folders that contain that file, down to the main git folder, get added as well, so you'll now have /plugin1/ tracked in git.

Go through, use git add /path/to/file on any of those (?) c source files you have, and then commit the changes, via git commit /path/to/file. Generally, anything that's pure text, it's good to be added to the repository, of course.

Finally: Be aware that git status is only designed to tell you about modified, tracked files, including newly added files. If there are no modifications, it'll just give you mostly blank output.

To see the files that -are- actually tracked by git, use git ls-tree HEAD which will only show you tracked files!

For a clean start

Here is how I generally start a git repository.

cd /path/to/project/
git init
echo "README" >> README
git add .
git commit -am "  Initial Commit of readme and files."

Upvotes: 2

Lazy Badger
Lazy Badger

Reputation: 97285

The important point about "git add ." is that it looks at the working tree and adds all those paths to the staged changes if they are either changed or are new and not ignored

And neither Git or Mercurial track empty dirs

Upvotes: 0

Joey Adams
Joey Adams

Reputation: 43390

You only added your README file. If you type git status, you will see that all of your other files are considered "untracked". You need to add them with git add so they will be tracked:

git add file1 file2 file3
git commit -m 'Added remaining files to repository'
git push

Upvotes: 0

Related Questions