Mercurial: qrefresh for select files
Say I have a number of files I have changed 开发者_运维问答such that when I do an hg status it comes up with something like:
M ../../file1
M ../../file2
M ../../file3
What if I only want to do a qrefresh for the changes I've made for file2 and implicitly abandon changes I've made to file1 and file3 such that they are reverted to their original state? Is there a way to do that with mercurial? I'm fairly new to the whole version control thing.
Since hg qrefresh
will automatically include all changes, you only need to exclude certain files, and the refresh will actually drop all changes of those files from the patch. Then you can revert the files.
This refreshes everything but file1
and file3
in the patch (the patch now contains no changes of either):
hg qrefresh -X ../../file1 -X ../../file3
Now file1
and file3
still have some changes and need to be reverted:
hg revert ../../file1 ../../file3
This will change the current versions to ../../file1.orig
and ../../file3.orig
, just in case you find you need the changes again. You can also add the --no-backup
switch and those won't be created.
You could also do this in the opposite order:
hg revert ../../file1 ../../file3
hg qrefresh
The refresh doesn't need arguments this time because it will see no changes in those 2 files compared to the parent of the working directory, and thus will disappear from the patch (refreshing the patch basically re-writes the patch). This is the way I would do it, but I also wanted to demonstrate the -X
switch.
Check out hg help revert
and hg help qrefresh
for more.
精彩评论