Can I fix the incorrect file transfer to Mercurial much later?

We were all there at some point - you move the file using something other than the Mercurial command hg move, and commit and push your changes only to acknowledge your mistake much later. Is there a way to tell Mercurial later that there is a connection between the "old" path and the "new" path?

I tried playing with --after, but that just seems like a mistake, unless you catch the problem before committing a set of changes:

  > hg move OLD_PATH NEW_PATH --after
  OLD_PATH: The system cannot find the file specified
  abort: no files to copy

In my specific situation, this change was made by a colleague through a dirty private branch (or two), and then merged with our branch defaultand moved to our main repo, so it has already spread to the whole team.

Any ideas?

+4
source share
1 answer

First of all, are you sure that the renaming was not detected? Mercurial, by default, detects moves where the file remains unchanged (that is, where it was not renamed + edited), and writes it as a rename. Make sure this was not detected with hg log -f NEW_PATH.

If this was not written as a rename, make a branch from the old commit with the correct rename and merge:

hg update -r ORIGINAL_COMMIT    # Go to the commit before the rename
hg move OLD_PATH NEW_PATH       # Record the rename
hg commit                       # Commit the rename
hg update default               # or whatever your main branch is
hg merge -r tip --tool :other   # '-r tip' is technically optional
hg commit                       # Commit the rename to the main branch
hg log -f NEW_PATH              # Verify that it worked

, --tool :other "" ( , ) .


: , evolve. ( hg amend hg commit --amend hg commit --amend) ( hg evolve --all) [1]. , evolve; , , / ( ). , , , , , ; , , Mercurial, . : , .

[1] , hg evolve , , . hg log --hidden ( --hidden).

+4

Source: https://habr.com/ru/post/1606847/


All Articles