Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding file to git's stage does nothing and cannot be committed

Tags:

git

I have gotten myself into a bizarre situation where in one of my branches a web.config file cannot be added to the stage. The output of

git add path/to/web.config git status 

Is the same as as before the file was added. Web.config appears to require modifications and has not been added to the stage.

Perhaps more interestingly, when I delete the Web.config from the file system and run git status I get output that indicates I have two web.config files that are ready to be deleted and are not staged.

# Changes not staged for commit: #   deleted: path/to/Web.config #   deleted: path/to/web.config 

Note that one has and uppercase W and the other a lowercase w. The file that I removed on the actual file system is an uppercase 'W'.

Edit 1

The output of git ls-files --stage shows that there are indeed two files that differ by case in the index.

100644 63cd5911b9b12bbad559bb69b1b596708b932061 0 path/to/Web.config 100644 d60ab44bb38f05ffce126ddd3c3293b06e6e4096 0 path/to/web.config 

I output each of these to a file with git cat-file -p <hash> > <file> and compared the two files. While the textual content is the same, the uppercase Web.config contains CRLF endings and the lowercase web.config contains lowercase endings.

Edit 2

With the file physically deleted from the file system git reset HEAD produces this output but the file is not restored on the file system and therefore cannot be added.

Unstaged changes after reset D    path/to/Web.config D    path/to/web.config 

I want the file in the working directory to have CRLF as I am working on Windows but I would like for text files to be stored with LF in the internal Git database. So, I assume that would be 63cd591 but I could be off base here.

How do I permanently remove path/to/web.config from the index in this scenario? I am on Windows and cannot have two files on my path that differ only by case.

like image 358
Ryan Taylor Avatar asked Jul 22 '13 22:07

Ryan Taylor


People also ask

Why my git add is not working?

This is because the node_modules folder is not ignored and hence when we run git add . command git visit all your directory/files and sub directory/files which is not ignored in . gitignore hence it is taking so long time to process it as node_modules contains a large amount of files and folder.

How do I add files to a git staging area?

Add files to the staging area by using the "git add" command and passing necessary options. Commit files to the local repository using the "git commit -m <message>" command. Repeat.

What happens when you stage files in git?

A staging step in git allows you to continue making changes to the working directory, and when you decide you wanna interact with version control, it allows you to record changes in small commits. Suppose you have edited three files ( a. html , b. html , and c.


2 Answers

The final solution to this particular problem was to remove both web.config entries from the git cache, commit any changes, and re-add the desired Web.config file back to git.

git rm --cached path/to/Web.config git rm --cached path/to/web.config git commit -m "Repair confused cache" git add path/to/Web.config git commit -m "Add Web.config" 
like image 110
Ryan Taylor Avatar answered Oct 04 '22 11:10

Ryan Taylor


Typically when git gets into a confused state, removing and re-adding the file to the cache will fix it:

git rm --cached foo 

It seems the most common way that a file gets in the confused state, is when performing a mv from the command line.
I've found that using git mv instead of mv helps to prevent running into this issue. http://linux.die.net/man/1/git-mv

Lastly, If you are going to delete a file from a git repository, use git rm instead of just rm
Why use 'git rm' to remove a file instead of 'rm'?

https://www.kernel.org/pub/software/scm/git/docs/git-rm.html`

like image 45
spuder Avatar answered Oct 04 '22 10:10

spuder