0

I've just submitted a PR for my colleague, and come to an (obvious) "issue".

Basically, I've copied 50+ files, and made changes to certain lines. In our system, we append _2 or _3 to the file to signify version number.

In the pull request, it shows every line in these 50 files as new lines, thus it would be incredibly hard to review these files.

My question is, does git have a way for me to basically say "Don't consider this file as new, consider it a duplicate of X with changes."

I know my colleague can just diff the two files manually, but I'd like it to show in the PR too.

Mad Physicist
  • 107,652
  • 25
  • 181
  • 264
Kevin
  • 979
  • 4
  • 10
  • 22

2 Answers2

1
  1. git only keeps the resulting content of your operations ,
  2. it does not keep information about how you reached this state.

i.e :

  1. it stores a commit with 2 files file and file_2 with very similar content,
  2. it does not make difference between "file_2 was initially copied from file" vs "file_2 started empty and I typed back the whole content of file into it"

There are some options to ask git diff to detect renames and copies (see "Record file copy operation with Git" which I suggested as a duplicate), I don't think github's GUI has a way to activate these options when displaying the diff for a PR.

LeGEC
  • 46,477
  • 5
  • 57
  • 104
  • That being said, I agree with @MadPhysicist 's comment : if you are already using a versionning system, you shouldn't need to version files within each commit on top of `git` – LeGEC Dec 13 '18 at 08:49
-1

You can follow the below steps. I am just giving example for file1. You need to do the same for other files.

mv file1 file1_version
git rm file1 #remove file1 from git tracking
vi file1_version #make file version changes, assuming you use vi editor
git add file1_version #add file1_version for tracking
git commit -m"rename and adding file"

Now, git will be able to find out whether file is changed based on the content.

For more information, read this stack overflow answer

Venkataraman R
  • 12,181
  • 2
  • 31
  • 58