0

I apologize if this is a newbie question, but I've been search around and I'm dumbfounded as to why this is.

I have some files I'd like to add and commit.

I run:

git add . I also tried git add -A, git add -f -A

git commit -m 'message'

git log --graph --decorate --pretty=oneline --abbrev-commit master origin/master temp (to make sure my master branch is on the latest commit)

git push origin master

Yet there are no changes. The push was successful. But the files are not being added to my repository. What could be the reason?

EDIT:

I should mention that Git doesn't seem to be detecting new files. When I specify the exact file to add, such as git add myapp/newFile.html. I get an error message fatal: pathspec 'myapp/newFile.html' did not match any files. The file is clearly in the folder.

EDIT 2:

I tried re-making my folder with rm -rf .git and then re-doing all the steps. But when I do git add -A again, the new files are still not being added! My folder feels like it's cursed or something.

EDIT 3:

Results from ls -la

drwxr-xr-x 0 valachio valachio   512 Jan 11 20:35 .
drwxr-xr-x 0 valachio valachio   512 Jan 11 20:17 ..
drwxr-xr-x 0 valachio valachio   512 Jan 11 19:43 bungol
drwxrwxrwx 0 valachio valachio   512 Jan 11 19:43 config
drwxrwxrwx 0 valachio valachio   512 Jan 11 20:41 .git
-rwxrwxrwx 1 valachio valachio   804 Jan 11 19:43 manage.py
drwxrwxrwx 0 valachio valachio   512 Jan 11 19:43 misc (non-coding related stuff)
-rwxrwxrwx 1 valachio valachio   327 Jan 11 19:15 Pipfile
-rwxrwxrwx 1 valachio valachio 13798 Jan 11 19:43 Pipfile.lock
-rwxrwxrwx 1 valachio valachio    38 Jan 11 19:15 Procfile
-rwxrwxrwx 1 valachio valachio   115 Jan 11 20:08 README.md
-rwxrwxrwx 1 valachio valachio   368 Jan 11 19:43 requirements.txt
-rwxrwxrwx 1 valachio valachio    12 Jan 11 19:43 runtime.txt
drwxr-xr-x 0 valachio valachio   512 Jan 11 19:43 staticfiles

Results from git ls-tree HEAD

100755 blob a0994e0c2c674f7964b97e73bf8b639e0bd15fa3    Pipfile
100755 blob 79baf37feb267b9479d4b8979623e9164d8d17c3    Pipfile.lock
100755 blob 2a05d1701bb03f8e565ccb53b5048a2ecbb8ea81    Procfile
100755 blob 0fa4a27c2e5a6e03c3edf2eb096766c20c0e9206    README.md
040000 tree c1179776614cf441fd04a5241b91869e3b24a776    bungol
040000 tree 8f0028f91df90b5124315f5e1cdd776c55fe2300    config
100755 blob 68141ee9e00d47db18f3598190234e8f8818dd5d    manage.py
040000 tree 4209dc1c056f595660ebf39ed57dc5bf72841597    misc (non-coding related stuff)
100755 blob d108cb2bdc916228474253e8c014dd1944df27f2    requirements.txt
100755 blob 5f61493782f81ae7c642d97051a8be79da5b7dba    runtime.txt
040000 tree a044a50441ede0a7718934b096f3c11ef4e5c2ae    staticfiles

EDIT 4:

I found the problem. I am using Ubuntu and the new files did not have access permissions. I had to give the current user access permissions to those new files with chmod 755 and after that it works.

Sorry I didn't mention this in the original question. Thank you to everyone that provided answers.

anthony sottile
  • 61,815
  • 15
  • 148
  • 207
Valachio
  • 1,025
  • 2
  • 18
  • 40
  • 2
    Can you post the output of `git status`, before and after running `git add *` ? – Grumblesaurus Jan 12 '18 at 01:25
  • 3
    Do you have a `.gitignore` file that may be excluding the files you want to add? – Khalos Jan 12 '18 at 01:27
  • what if you `git add myapp` ? – Gilles Gouaillardet Jan 12 '18 at 01:29
  • @JoshuaD I get the following - `On branch master nothing to commit, working directory clean` – Valachio Jan 12 '18 at 01:30
  • 2
    Please show the results of these three commands `ls -la` and `git ls-tree HEAD` and `cat .gitignore` – Grumblesaurus Jan 12 '18 at 01:41
  • 1
    After you did `git commit -m 'message'` what output did you see? – Code-Apprentice Jan 12 '18 at 01:44
  • @JoshuaD Added. Doing `cat .gitignore` gives me `cat: .gitignore: No such file or directory` – Valachio Jan 12 '18 at 01:47
  • 1
    More commands to try and add the output to your question: `git log` and `git reflog`. – Code-Apprentice Jan 12 '18 at 01:56
  • 1
    Also, which new files are you attempting to add? – Code-Apprentice Jan 12 '18 at 01:56
  • 1
    All of the files which show in `ls -la` are also shown in `git ls-tree HEAD`. This means that all of those files have been committed to git. What are you seeing that makes you think that the files aren't added? – Code-Apprentice Jan 12 '18 at 01:58
  • @Code-Apprentice When I check my repository after the commit finishes, the new files are not there. Also when I set up a fresh new folder and did `git add .`, the new files are still not being added. – Valachio Jan 12 '18 at 02:03
  • 1
    Which repository are you checking and how are you checking it? – Code-Apprentice Jan 12 '18 at 02:04
  • 1
    Are you on branch master? That's the only branch you're pushing up to ghithub. `git branch` to see what branch you're on. – Grumblesaurus Jan 12 '18 at 02:10
  • @Code-Apprentice I'm using Heroku and also a GitHub repo so I can do `git push heroku master` or `git push origin master` and I can check both places to see that the files were not committed. I can see the log when I do `git add -A` that the new files aren't being added. So it's something wrong with `git add` – Valachio Jan 12 '18 at 02:13
  • 1
    What is the output of `git remote -v`? – Code-Apprentice Jan 12 '18 at 02:19
  • @Code-Apprentice I found the problem. It was a file permissions issue with Ubuntu. Once I gave the current user permissions to the new files, it worked fine. I should've mentioned this in my original question. Thank you for your help! – Valachio Jan 12 '18 at 02:21

4 Answers4

3

Let's clarify a few concepts of git:

  1. Your local directory is a git repository. All git commands interact with the local repository in some way. Some commands also interact with a remote repository

  2. git add . will all files in the current directory to the staging area of your local repository. Whenever you do this, git will always add the files because this is how git works. Note that "adding" files only stages them for the next git commit.

  3. git commit creates a commit in your local git repository with the files that you have previously added to the staging area. Again, this command will always do this. In fact, the output from git ls-files in your post proves that all of your files have been added and committed to your local repository.

  4. Your local repo can be connected to remote repo on GitHub or any other sever running git. If you do git clone, your local repo will have a remote named origin which points to the repo which you cloned. If you do git init instead, you can use git remote add to add a remote with whatever name you wish.

  5. Once you have a remote repo configured in your local repo, you can use git push to push commits from your local repo to the remote one. Likewise, git pull will pull commits from the remote to your local repo.

Code-Apprentice
  • 81,660
  • 23
  • 145
  • 268
1

Try git add * and git add .*.

Grumblesaurus
  • 3,021
  • 3
  • 31
  • 61
  • `git add *` has no effect. `git add .*` gives me the following error - `fatal: ..: '..' is outside repository` – Valachio Jan 12 '18 at 01:30
1

If it doesn’t detect changes then you could start over. Simple delete your .git file from the directory and reinitialize again. This might not be a good practice but if you’re new in git then sometimes this kind of fix helps.

Also make sure your user access credentials are setup correctly.

Abu Shoeb
  • 4,747
  • 2
  • 40
  • 45
  • I did that. I also tried to start the project in a completely new folder. All the old files were added and committed fine. But the new files are not being added. – Valachio Jan 12 '18 at 01:44
  • Ok just to make sure that you have a git repo. So you remove the .git from the directory. Then you do git init. And then you git remote add origin your-git-name. Have you done all these steps? – Abu Shoeb Jan 12 '18 at 01:50
0

This issue can arise on freshly cloned projects. Don't forget to check if this repository uses Git Submodules a.k.a. nested reps. No matter how many times you git add -A && git commit; as an extra step you will have to navigate to the nested folder and commit there too. Only then, you will finally get a nice and clear git status output.

On a side note, I you don't want this submodule and you one to track everything from the parent repository you can refer to this post: https://stackoverflow.com/a/1759990/11239755

Mike Bendorf
  • 460
  • 6
  • 7