0

I cloned a git repository into my local machine I replace four files in my physical location. Performing

git status

yields following results

On branch XXX Changes not staged for commit: (use "git add ..." to update what will be committed) (use "git checkout -- ..." to discard changes in working directory)

    modified:   ABC.xml
    modified:   XYZ.java
    modified:   DBCD.java
    modified:   sdfsd.java

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

Thereafter, I do

git add --all

get following messages:

warning: LF will be replaced by CRLF in ABC.xml.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in XYZ.java.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in DBCD.java.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in sdfsd.java
The file will have its original line endings in your working directory.

Now when I do

git status

The following messages that display seems to indicate that git has lost track of the files. They do not appear under Changes to be committed section

On branch XXX
nothing to commit, working directory clean

Also, these four files become read only mode.

Also, git whatchanged does not indicates that file got committed.

Not sure what wrong I am doing ? Shall I simply commit ? Also, what happens when

git add --all

happens ?

Update: I repeated this entire process once more changing just one thing. Instead of using

git add --all

I used

git add ABC.XML

Even now, similar thing happens. ABC.XML file does not appear under Changes to be committed section. Git Status does not show status of ABC.XML however, All other files still show on git Status

DolphinJava
  • 2,682
  • 1
  • 23
  • 37
  • 1
    This link might help you http://stackoverflow.com/questions/572549/difference-between-git-add-a-and-git-add/16162511#16162511 – Gopi Jul 28 '14 at 17:33
  • I just repeated the entire above process once more. Only difference I did was instead of using **git add -all**, I did git add ABC.XML Then doing **git status** enlists other three files in **Changes not staged for commit** category, however the ABC.XML does not appears in **Changes to be committed** category. Therefore, I believe that your link may not help here. – DolphinJava Jul 28 '14 at 17:35
  • My git version is git version 1.9.4.msysgit.0 – DolphinJava Jul 28 '14 at 17:39

3 Answers3

2

This is a result of your line-ending conversion settings. Your files in your working directory have different line endings than what was stored in the last commit, so to git status, they appear to be different files (size is different, hash doesn't match). However, when you do a git add, and it converts the line endings for the purpose of adding the file to the repository, it finds that the file after conversion matches the file as it was last committed, which means there are no changes to the file. A side-effect of git add is that the index is updated with the current timestamp of your files, and so git status after your git add sees that the timestamp hasn't changed and doesn't check the size and hash on the second run.

You can run compare the output of git diff and git diff -b (ignoring whitespace/line ending changes) to also see the differences - at least before you git add...

twalberg
  • 59,951
  • 11
  • 89
  • 84
  • I deduced from your information shared that if I do any extra edit in each of the four files, say just add another blank line, `git add` will not find a match between the new file and the file that was last committed. Thus, it will output the files in modified. This theory has proved right. Thank you for your guidance. It really helped. :) – DolphinJava Jul 28 '14 at 19:20
  • This also highlights that the four files were not actually different. Weird. This would not have happened if the files had been actually changed. – DolphinJava Jul 28 '14 at 19:31
0

If I understand your question properly.

If you have 4 files to be committed. Then you can simply do.

git commit -a

Where all the modified files will be committed at once , as a single commit (One SHA)

Gopi
  • 19,784
  • 4
  • 24
  • 36
  • I can do so, however according to this link of ProGit http://git-scm.com/book/en/Git-Basics-Recording-Changes-to-the-Repository , Under **Staging Modified Files** section, it clearly talks about using git add to stage a modified, already tracked file. Something is not right or unexplained. – DolphinJava Jul 28 '14 at 17:44
  • Yes files need to be staged before committing so that the changes in the files are not lost. If you are facing issue with git add -A try adding files individually and doing a commit or do a "git commit -a" – Gopi Jul 28 '14 at 17:47
  • I have updated my question. I have facing same issue when I try to add files individually. – DolphinJava Jul 28 '14 at 17:51
  • 1
    I don't understand when you say it disappears. Since you have staged that file you are not seeing it as "files to be staged". Try adding all the files do a commit and check the "git log" it should show all the 4 files committed – Gopi Jul 28 '14 at 17:54
  • Disappear meant 'git status' does not show status of the file. It shows status of rest of the files. I would expect the file to be listed under category of **Changes to be committed** – DolphinJava Jul 28 '14 at 17:59
0

I realized a fact now which I should mention here. It seemed irrelevant to me earlier. The bigger picture of this activity is that I am migrating a codebase from ClearCase to Git. Last week I migrated the complete codebase, however this week I was informed that four of those migrated codebase files were not merged by me. So these files were merged by a third person. I updated my codebase today and did copy paste method. I copied the files from a VOB on my machine without checking out. The files were in read only mode.

The files remain read only after I placed them in my local GIT repository and ran git add then as @twalberg quoted in his reply, git add tries to convert line endings but is unable to do so because files are read only. The command terminates, and I guess the files proverbially land in no mans land therefore git status does not show what to do.

I need to checkout these files in Clearcase and then try copy pasting.

DolphinJava
  • 2,682
  • 1
  • 23
  • 37