Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git: add not staging files

Tags:

git

Thank you in advance for reading - this might be a very trivial problem for the Stackoverflow community, but driving me crazy.

I encountered a very bizarre problem this afternoon doing some routine work with git.

After making some changes to a file in a text editor, I went to the terminal to stage and commit. After attempting to stage the file with git add (like always) I went to commit git commit -m the terminal spit this out at me:

no changes added to commit (use "git add" and/or "git commit -a")

I tried staging again (because as a good human being I decided to just try again and expect different results) and yielded the same results. I checked 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) modified:   ../../Round 1/R1C3/R1C3.py

After some searching around on the tubes I discovered that I could stage the file in various other ways, but not with git add. I could use git add -A or git add -u or stage using interactive staging.

Baffled and not really understanding why my reg git add wasn't working, I forged on using git add -A. The story gets weird. After a restart on my machine (2011 Macbook Air running Mavericks) I tried good ol' git add again on the same file after some changes...and guess what? IT WORKED. So I continued on.

Now, a short time later, I have the same problem again. git add will not work (same directory).

Does anyone have any idea what I am doing wrong? It isn't a really big problem, because of the aforementioned alternatives, but I would like to understand why this is happening. Especially because this has always worked for me in the past, and now today, it broke :(

**NOTE: My other version controlled projects on my computer don't seem to be affected.

git add R1C3.py
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)
#
#   modified:   ../../Round 1/R1C3/R1C3.py
# no changes added to commit (use "git add" and/or "git commit -a")

git add -A
git status
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#   modified:   ../../Round 1/R1C3/R1C3.py
#
like image 790
Marrrrrrk Avatar asked Jan 26 '14 00:01

Marrrrrrk


1 Answers

When you do a git add it should be run in the same directory as the file or passed a relative path to the file. Since the file is located in the parent directory, git add will not find the file. In your case, you should cd ../../Round 1/R1C3/ and then run git add R1C3.py.

git add -A, works because it stages all files in your repository, disregarding where you are in the directory.

like image 111
dqiu Avatar answered Sep 28 '22 17:09

dqiu