Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git: I can add a directory, but at commit time I get "nothing to commit"

I'm trying to add two directories to a git repo. I can add them OK, but when trying to "commit", I get "nothing to commit". I'm following the add->commit->push sequence, but in this case it doesn't seem to be working. I have already pulled everything from the repo.

Any hints? thanks!enter image description here

like image 352
Mani Nilchiani Avatar asked Dec 25 '12 20:12

Mani Nilchiani


People also ask

Why does it say nothing to commit?

The Git “nothing to commit, working directory clean” message tells us that we have not made any changes to our repository since the last commit. If this message appears and the contents of your remote repository are different to your local repository, check to make sure you have correctly set up an upstream branch.

How do I commit a directory in Git?

Enter git add --all at the command line prompt in your local project directory to add the files or changes to the repository. Enter git status to see the changes to be committed. Enter git commit -m '<commit_message>' at the command line to commit new files/changes to the local repository.

Do I need to Git add before commit?

When do you use git add ? As you're working, you change and save a file, or multiple files. Then, before you commit, you must git add . This step allows you to choose what you are going to commit.

Does Git commit empty folders?

Git doesn't like empty folders. It doesn't include them in commits and it certainly doesn't include an empty directory when you push to GitHub or GitLab.


3 Answers

You will be able to commit as soon as you make a change to/add a file. Adding a directory to git can't be commited itself; you need to add/edit a file inside the directory.

Try adding something in css and comitting afterwards.

like image 160
sTodorov Avatar answered Sep 21 '22 21:09

sTodorov


Git only tracks files - when you run git add <directory>, what you're actually doing is telling Git to add the contents of any files in that directory. Since the directory is currently empty, it doesn't add anything, and thus there's nothing to commit.

For instance, the following would work:

$ touch css/main.css
$ git add css
$ git commit -m "Add empty main CSS file"
like image 21
Amber Avatar answered Sep 20 '22 21:09

Amber


As everybody says, git track only files, not directories. So you can't add empty directory into it. You can make a trick by adding empty .gitignore in directory css and commit it.

like image 32
Viacheslav Kondratiuk Avatar answered Sep 19 '22 21:09

Viacheslav Kondratiuk