What does `hg cp` do and how to "undo" it?

80 Views Asked by At

I used Visual Studio Code (VSC) at work, and like usual, I view a file, such as

Foo.react.js

and use Save As

Bar.react.js

so as to create a new component file using Foo.react.js as a template.

However, when it got to CI/CD (Jenkins) and the push to production server stage, the file Bar.react.js had merge conflict with itself, which is strange, because why would a new file that only I created and edited conflict with itself?

Talking to the hg and CI/CD team, they told me that VSC (in my company) does an hg cp when we use Save As, and it treated Bar.react.js to follow the history of Foo.react.js.

So possibly somebody also modified Foo.react.js, and some lines in Bar.react.js conflicted with it.

I was also told that I can use hg forget Bar.react.js and then hg add Bar.react.js to fix the issue.

So the question is:

  1. What exactly does hg cp do and why would it want to track history for a new file using an old file?

  2. Is it true that I can only do hg forget Bar.react.js and then hg add Bar.react.js for the current commit and push, to fix the issue? If I didn't use hg forget and hg add and then fixed that merge conflict and now all the files are finally in the repo, can Foo.react.js still conflict with Bar.react.js in the future?

The reason I think for (2), they may not conflict with each other in the future is that, if I do hg forget and hg add after all files are in the repo, then hg treats that as "nothing changed" and I cannot even commit. If I hg forget and commit, and then hg add and commit again, and now I want to land and push this, the CI/CD would say that the hg forget commit does not pass the CI/CD tests (missing component), so I really wonder if I need to go through the hg forget and hg add because it seems nobody ever does that as nobody ever stated how it can be done once the files are all in the repo now.

So it becomes:
Now that all files are in the repo now, do I still need to do hg forget Bar.react.js and then hg add Bar.react.js so that these two files do not conflict with each other in the future. If I need to do the hg forget and hg add, how should it be done?

1

There are 1 best solutions below

1
Tom On
  1. What exactly does hg cp do and why would it want to track history for a new file using an old file?

Tracking history of renamed files is very useful.

Say you been working on button.jsx for many years, and then it's renamed to colorButton.jsx. Without tracking history across renames, when looking at the history of colorButton.jsx, you would only see the history since it was renamed, as it would be considered a new file. Since button.jsx is no longer in the working directory, it might also be hard to know where the old history was.

copying / duplicating files is not as common, but I guess if you do want to duplicate the file, and maintain the common history it would be useful.

  1. Is it true that I can only do hg forget Bar.react.js and then hg add Bar.react.js for the current commit and push, to fix the issue?

one can also break the association between the two files with:

hg rename --forget colorButton.jsx

Note:

one can read about this by typing

hg help rename

or

hg help copy