Reputation: 6410
With hg, how can I replace the contents of a directory in one change?
More specifically, I have headers for a large C++ library checked into my repo and I'd like to update them (including adding and removing files) to the latest version of the library. And I'd like to do this in one change, rather than first a removal of the old version and then addition of the new, which would break tests and produce unhelpful diffs.
Upvotes: 1
Views: 210
Reputation: 5821
# Change to parent directory of your vendor directory
cd vendor_dir/..
rm -rf vendor_dir
# unpack/copy/checkout new vendor sources into a new vendor_dir
# Tell mercurial to figure out what changed
# Feel free to play with the similarity percentage and the (-n) do nothing switch
hg addremove --similarity 70 vendor_dir
hg commit vendor_dir
Updated:
hg rm *
within vendor_dir
misses dot files, if any. hg rm
to rm -rf
because I wrongly assumed that addremove after rm would do the right thing. Hint: it doesn't.Upvotes: 4
Reputation: 28390
If they are all changed then, (assuming a flat directory structure:
hg remove \path\to\directory\to\replace\*.h
copy \path\to\new\files\*.* \path\to\directory\to\replace\
hg add \path\to\directory\to\replace\*.*
hg commit -m "Library SoAndSo headers replaced"
hg push
The first line says forget all the files on the next commit but then the new ones are added in the same commit - remember only the last but one line actually changes the local copy of the repository and it only becomes public on the last line.
If you do have sub-directories then you can just remove the *.h
on the first line, use xcopy
or explorer to copy the new directory structure into place and remove the *.*
on the 3rd line.
Upvotes: 2