Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to force Git to commit a file if it is recognized as unchanged

Tags:

I have 2 binary files, which have

  • exactly same size
  • exactly same modification date
  • exactly same creation date

but

  • different content

If I replace one file with the other, git does not recognize this file as changed.

Filesystem: NTFS, OS: Windows 7, Git Version: 1.9.0

(my workaround is to edit this new file to get a new modification date but I keep same content)

How can I force Git to commit the new file?

like image 894
ToBe Avatar asked Mar 26 '14 15:03

ToBe


People also ask

How do I force a git commit?

The --force option must be used to push an amended commit. The above example assumes it is being executed on an existing repository with a commit history. git commit --amend is used to update the previous commit. The amended commit is then force pushed using the --force option.

How do I commit just changed files?

Enter git add --all at the command line prompt in your local project directory to add the files or changes to the repository. Enter git status to see the changes to be committed. Enter git commit -m '<commit_message>' at the command line to commit new files/changes to the local repository.

How do you force Add all files in git?

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. We also say that they will be staged.

Can you commit without adding?

Without adding any files, the command git commit won't work. Git only looks to the staging area to find out what to commit. Staging, or adding, files, is possible through the command line, and also possible with most Git interfaces like GitHub Desktop by selecting the lines or files that you'd like to stage.


1 Answers

You could always do

git rm --cached <file> git add <file> 

This should put the new file into the index regardless of what was previously there.

like image 184
user3426575 Avatar answered Oct 09 '22 10:10

user3426575