0

I've one folder with ~300 files and ~30 folders. I did cut the folder(Ctrl+X) and pasted(Ctrl+V) on the expected folder.

Then I only did a git add -A.

After doing a git status, I would say that 95% of the files are correctly considered as "renamed", but some of theme are "deleted"+"new file".

I can't find any logic that would regroup the non-renamed files.

What is the issue here? And how do you think I can resolve it?

(I've git version 2.18.0.windows.1)

J4N
  • 19,480
  • 39
  • 187
  • 340
  • 1
    Possible duplicate of [How to make git mark a deleted and a new file as a file move?](https://stackoverflow.com/questions/433111/how-to-make-git-mark-a-deleted-and-a-new-file-as-a-file-move) – garlix Sep 05 '18 at 13:11
  • @garlix Dude, read the question, I did exactly what is marked as "answer" in the given link, and it doesn't work for some of my files. – J4N Sep 05 '18 at 13:12
  • 1
    *"And how do you think I can resolve it?"* -- there is nothing to *"resolve"* here. Git does not record the file renames in the commits. It detects a potential rename when it runs `git status`, `git diff` (and some other commands) by comparing the content of the files. – axiac Sep 05 '18 at 13:15
  • @axiac So why does it think the files are different? I only did a cut-paste, I didn't even opened them in any application. – J4N Sep 05 '18 at 13:17
  • @J4N how exactly your question differs from the one I linked? – garlix Sep 05 '18 at 13:17
  • @garlix the one you mentioned didn't do the `git add -A`. Which is supposed to handle the "removed+new file" to "renamed". (which I did and didn't work for all my files). – J4N Sep 05 '18 at 13:20
  • can you run `git status -s`, and add to your question the two lines corresponding to one sample of a "deleted + added" file ? – LeGEC Sep 05 '18 at 14:08
  • 3
    @J4N - I don't know why you think `git add -A` has anything to do with handling renames. If that's what "makes this question different", then this question is not different. – Mark Adelsberger Sep 05 '18 at 14:13
  • Would using the`git mv` have gotten a different result? @MarkAdelsberger? – Todd Sep 05 '18 at 20:00
  • 1
    No. No matter how you perform the move operation, git does not track moves. There might be some explanation for why some files are being properly detected and others not, but without knowing more about the files we can't answer that, and there's really nothing else to answer here. I understand you WANT git to behave "correctly" here, but move detection is a limitation of git's design. – Mark Adelsberger Sep 06 '18 at 01:31
  • @Todd yes it would but usually I've a lot of files to move at once, and Visual Studio doesn't seems to be able to do git mv. – J4N Sep 06 '18 at 05:33
  • @MarkAdelsberger Not what the community seems to say: https://stackoverflow.com/a/433142/397830 – J4N Sep 06 '18 at 05:35
  • @J4N - I'm not sure what part of that answer you think contradicts me, but it doesn't actually matter. The facts are as I've spelled them out. Since you want to argue about it, and I'm not going to, you're welcome to find out the hard way on your own. – Mark Adelsberger Sep 06 '18 at 12:43

1 Answers1

-1

One blind guess : all line endings have changed, so git treats the two files as different

git may alter the content of the files when you git add them.

The most common case is the way it handles crlf line endings : see this SO answer for example.


You can manually inspect the difference between the "deleted" version and the "added" version :

 # compare the content of 'old/file' as stored in the HEAD commit,
 # and 'new/file' as stored on your disk :
 git diff HEAD:old_deleted_dir/file  :new_added_dir/file

The : before the "new file" is relevant : git will use the indexed version of the file (the one that is added into its cache)

LeGEC
  • 46,477
  • 5
  • 57
  • 104
  • This returns nothing to me. Like I said, I didn't even opened those files, so I'm not sure who would have modified anything. – J4N Sep 06 '18 at 05:35
  • @J4N : you should check the *indexed* version of the file ; updated my answer accordingly – LeGEC Sep 06 '18 at 08:06