feedfood
feedfood

Reputation: 105

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

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....

Upvotes: 6

Views: 154

Answers (4)

StayOnTarget
StayOnTarget

Reputation: 13008

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").

Upvotes: 0

pyfunc
pyfunc

Reputation: 66709

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

Upvotes: 8

Alex
Alex

Reputation: 641

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 "."

Upvotes: 3

Lasse V. Karlsen
Lasse V. Karlsen

Reputation: 391326

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.

Upvotes: 1

Related Questions