Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git adding "unchanged" files to the stage

For a project I'm working on, I want to use:

git add . -A

to add some files to the stage. The problem is that Git thinks these files are unchanged from the last commit, so they are ignored. However, I personally changed the file, but Git still sees the file as unchanged.

How can I "forcefully" add that single file to my repository?

like image 711
user2744374 Avatar asked Sep 03 '13 20:09

user2744374


People also ask

How do I add all files to stage?

The easiest way to add all files to your Git repository is to use the “git add” command followed by the “-A” option for “all”. In this case, the new (or untracked), deleted and modified files will be added to your Git staging area.

What is assume unchanged in git?

When the "assume unchanged" bit is on, the user promises not to change the file and allows Git to assume that the working tree file matches what is recorded in the index. If you want to change the working tree file, you need to unset the bit to tell Git.

How do I force git to add a file?

The git add command can be used to add ignored files with the -f (force) option. Please see git-commit[1] for alternative ways to add content to a commit.

Are staged changes saved to git?

Once you are happy with the staged snapshot that is provided you commit it to the project history with git commit. Remember, git commit is saving changes in Git. You can also use the git reset command to undo a commit or staged snapshot when/if needed.


2 Answers

It seems like the assume-unchanged-bit is set for that file. With that bit set, git will not look for changes of that file anymore. Unset it by typing:

git update-index --no-assume-unchanged <file>

After that, git status as well as git add should detect the changed file.

like image 81
functionpointer Avatar answered Oct 23 '22 12:10

functionpointer


check your .gitignore file there must be some pattern matching this file which is excluding file from being staged. Or you can use git add . -f to forcely add these files.

like image 24
inampaki Avatar answered Oct 23 '22 14:10

inampaki