0

I just migrated my files from the old PC to the new. That includes a few development git repositories.

But I guess because the files were copied, the datestamps are different, and so git is now seeing them as uncommitted changes, even though there are no other changes to the files.

What is the best thing to do about this, just commit the files or is there some git magic (commands) to tell git everything is OK?

leoplaw
  • 53
  • 7

2 Answers2

0

git looks at the content of a file.

Modification dates are a trigger to indicate that the index should be recomputed, but if a file has the exact same content at the same place, it will not appear as "modiified".


In order to confirm that the files have different content, you can look at the hash that git computes :

# get the hash for the file in the current commit :
git ls-tree HEAD path/to/file

# compute the hash for the file on disk :
git hash-object path/to/file

If the hashes are equal, you may have hit an issue where the index wasn't properly refreshed, try running :

git update-index --refresh

to have git re-check all files (note : if files still appear as modified after that, please add a comment or update your question, there would indeed be something weird going on)

If the hashes are different, the contents are definitely different. You will have to look closer at what changed between the two versions of that file, for example by comparing the hex dump of each version.

LeGEC
  • 46,477
  • 5
  • 57
  • 104
  • Thank you for the reply and suggestion @LeGEC. I found a/the solution before reading your reply. The issue was I copied the repo from a Linux file system to a Windows, and thus losing some file information along the way. When I instead cloned the repo from Linux system to Linux, there were no issues. – leoplaw May 21 '21 at 12:29
0

TLDR: file copying repos and not git cloning them across different file systems (EXT4 vs NTFS/FAT32) will make git complain.

Full Answer:

When talking with a friend knowledgable in Git, he figured out the issue.

When migrating my data including the repo from the old PC which has a Linux file system to the new Linux PC, since I had no network connection, I copied everything onto a USB HD, which was formatted with a Window's file system, thus losing some file information and Git reporting everything had to be checked in again.

So the solution was to move the repo only over Linux file systems.

I set up a remote repo on a Linux file sever, pushed the local working repo from the old PC to the remote git server and then cloned the remote to the new PC.

Extra Points:

Cloning did not pull all of the remote branches. I found this solution for pulling all remote branches.

git-pull-all https://gist.github.com/grimzy/a1d3aae40412634df29cf86bb74a6f72

#!/usr/bin/env bash

git branch -r | grep -v '\->' | while read remote; do git branch --track "${remote#origin/}" "$remote"; done
git fetch --all
git pull --all

Thank you all for your help, your time and suggestions.

leoplaw
  • 53
  • 7