Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
+2 votes
2 views
in DevOps and Agile by (19.7k points)

I am struggling with Git, I can't seem to add my files. I ran ls to show that the files are in the current directory, then run git add . then git status which showed "nothing to commit".

JJ-Computer:first_app JJ$ git init

Reinitialized existing Git repository in /Users/JJ/rails_projects/first_app/.git/

JJ-Computer:first_app JJ$ ls

Diary.txt README.rdoc config.ru log   tmp

Gemfile   Rakefile  db    public    vendor

Gemfile.lock  app   doc   script

README    config    lib   test

JJ-Computer:first_app JJ$ git add .

JJ-Computer:first_app Jenn$ git status

# On branch master

nothing to commit (working directory clean)

JJ-Computer:first_app JJ$ 

 

2 Answers

+2 votes
by (62.9k points)

Your commands look correct (I've done them many times that way).

First, try

git add --all

and then try git status. I don't think that will solve it, but worth trying next.

Next try looking at your .gitignore file, if you have one (in the top-level where you did git init).

cat .gitignore

Remove any listings there that are causing your files to be ignored. For example, is there an entry with just *?

Next try:

git add --force

and then try git status.

If none of those work, I notice that your output from git init says "reinitialized" rather than "initialized", so something may have gotten messed up. If you've just initialized it and if it's Okay for you losing history, start over by removing the .git dir:

rm -rf .git

And then re-execute your same commands above. If that doesn't work, some more information about your setup will be required. For example, you might have a global .gitignore file: ~/.gitignore_global that need to edited (or removed if you don't want it).

0 votes
by (1.3k points)

Problem seems to be that Git is not finding any changes to be added. Possible causes and fixes include:

Unsaved Changes: Git only tracks saved changes in your working directory. Make sure that you have saved the changes you made to your files with your text editor.


New Files: Git will not follow new files created. When using ls, the files could be truly new, you will have to instruct Git to add them in using the command git add <filename>. Since you performed a git add., if they were saved, they should be added already; try to add them one by one and see if that is fine.

You may have a.gitignore file in your project directory. The.gitignore will tell Git which files not to track or which patterns should be ignored. You then cross-check whether the files that you wish to add lie on that.gitignore list. If they lie there, then even after saving and modifying, it won't track those for Git.

Line Endings: If the end lines your editor use are different than that which git uses, git would not recognize any of the changes done to the files. So, if your project originated on another operating system, it might be troublesome due to the line ending. You may want to look up for the line ending problem and convert the same accordingly.

Here is how you might proceed further for debugging:.

Check for unsaved changes: Open all your files in your text editor and make sure any unsaved changes are saved.

Try adding individual files: You can test this by using git add Diary.txt or any other filename you see in your working directory and then running Git to see whether it picked up the change
Check.gitignore: If the.gitignore file exists in your working directory, open it and inspect to see whether your files are included
Check line endings: Run dos2unix or unix2dos to change the line ending if that's necessary.
Once you have resolved any of these issues, try git add. and git status again. If Git recognizes them, you should see them listed under "Changes to be committed".

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...