How can I find parent file of one single file after copying?
Asked Answered
S

4

6

As title, If I do copy from one file to destination file, then I commit the change. Afterwards I want to find parent file of copied file, How can I do? for example...

hg copy file1 file2
hg ci -m "copy file1 to file2"

how to find parent of file2? If I use hg parents command, only find parent of changeset not file2.

thanks....

Senescent answered 6/12, 2010 at 9:37 Comment(0)
G
3

Use --template for format log:

hg log --template "{file_copies}\n" file2.txt

Filter empty strings (first line - in Unix, second - in Windows):

hg log --template "{file_copies}\n" file2.txt | grep .
hg log --template "{file_copies}\n" file2.txt | findstr /R "."
Gabfest answered 6/12, 2010 at 12:23 Comment(0)
N
8

hg log provides the facility

hgt $ hg log --copies -v b.py 
changeset:   1:a9c003a9bddb
tag:         tip
user:        "xxxxx"
date:        Mon Dec 06 01:40:01 2010 -0800
files:       b.py
copies:      b.py (a.py)
description:
copied file

Use the verbose mode and also --copies to find if the file has been used using hg copy command

Newfangled answered 6/12, 2010 at 9:49 Comment(0)
G
3

Use --template for format log:

hg log --template "{file_copies}\n" file2.txt

Filter empty strings (first line - in Unix, second - in Windows):

hg log --template "{file_copies}\n" file2.txt | grep .
hg log --template "{file_copies}\n" file2.txt | findstr /R "."
Gabfest answered 6/12, 2010 at 12:23 Comment(0)
N
1

Well, one way is that you can do a diff of the file:

hg log file2 -r 0:

If you know the changeset where it was introduced you should specify that after the colon:

hg log file2 -r 0:1

The output:

[C:\Temp\repo] :hg diff test2.txt -r 0:1
diff --git a/test1.txt b/test2.txt
copy from test1.txt
copy to test2.txt

But there could be better ways.

Neurocoele answered 6/12, 2010 at 9:45 Comment(0)
K
0

A direct way seems to be to use hg status.

Relevant options:

-C --copies              show source of copied files
   --change REV          list the changed files of a revision

For example, after the example in the question where file was copied to file2 assuming that was revision 12345:

hg status -C --change 12345

would yield something like this:

M path\to\modified1.txt
M path\to\modified2.txt
A path\to\file2
  path\to\file1

The last two lines reflect the added file and its origin.

The first two files could be some others that were modified in the same commit.

If you want to exclude files that were not copies, add the -a option ("show only added files").

Konrad answered 15/12, 2023 at 21:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.