I know that Mercurial can track renames of files, but how do I get it to show me renames instead of adds/removes when I do hg status
? For instance, instead of:
A bin/extract-csv-column.pl A bin/find-mirna-binding.pl A bin/xls2csv-separate-sheets.pl A lib/Text/CSV/Euclid.pm R src/extract-csv-column.pl R src/find-mirna-binding.pl R src/modules/Text/CSV/Euclid.pm R src/xls2csv-separate-sheets.pl
I want some indication that four files have been moved.
I think I read somewhere that the output is like this to preserve backward-compatibility with something-or-other, but I'm not worried about that.
hg status shows the status of a repository. Files are stored in a project's working directory (which users see), and the local repository (where committed snapshots are permanently recorded). hg add tells Mercurial to track files. hg commit creates a snapshot of the changes to 1 or more files in the local repository.
Once you decide that a file no longer belongs in your repository, use the hg remove command. This deletes the file, and tells Mercurial to stop tracking it (which will occur at the next commit). A removed file is represented in the output of hg status with a “ R ”.
There are several ways to do this.
Before you commit, you can use hg diff --git
to show what was renamed:
$ hg diff --git diff --git a/theTest.txt b/aTest.txt rename from theTest.txt rename to aTest.txt
Note that this only works if you used hg mv
, hg rename
, or mv
and hg addremove --similarity 100
.
After you commit, you can still use hg diff
, but you'll have to specify the change using -r
:
$ hg diff -r 0 -r 1 --git diff --git a/test.txt b/theTest.txt rename from test.txt rename to theTest.txt
For both hg status
and hg log
, use the -C command-line flag to see the source that a file was copied from.
$ hg status -C A aTest.txt theTest.txt R theTest.txt
The line just below aTest.txt indicates the source it was copied from (theTest.txt).
$ hg log -v -C changeset: 1:4d7b42489d9f tag: tip user: jhurne date: Tue Apr 20 20:57:07 2010 -0400 files: test.txt theTest.txt copies: theTest.txt (test.txt) description: Renamed test.txt
You can see the files that were affected (test.txt and theTest.txt), and that "theTest.txt" was copied from test.txt.
You can find out how many files have been renamed with hg summary. If you want to see the actual files that were renamed, the fastest way I've found is to do:
hg st -a -C
This will output something like this:
A <path\to\renamed\file> <path\copied\from> A <path\to\added\file> A <path\to\renamed\file> <path\copied\from>
Since hg status considers a rename to be a copy and a remove, your renamed files will list a copied from file. Files that were added but not renamed will not list a copied from file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With