Mercurial: Remove file from all changesets
I understand how to remove an entire changeset from history but 开发者_开发问答it's not clear how to remove a subset instead.
For example, how do I remove all DLL files from an existing changeset while leaving the source-code alone?
Because the revision ids (e.g. a8d7641f...) are based on a hash of the changeset, it's not really possible to remove a subset of a changeset from history.
However, it is possible to create a new repo with a parallel history, except for a certain set of files, by using the Convert extension. You'll be converting a Mercurial repo to a Mercurial repo, using the filemap to exclude the files you don't want by adding exclude
s. This will create a new, unrelated repository, which means that any clones people have won't be able to pull from it any more, and will have to re-clone from this new repo.
- Make sure all your teammates have pushed their local changes to the central repo (if any)
- Backup your repository
- Create a "map.txt" file with the following content:
# this filemap is used to exclude specific files exclude "subdir/filename1.ext" exclude "subdir/filename2.ext" exclude "subdir2"
- Run this command:
hg convert --filemap map.txt c:/oldrepo c:/newrepo
NOTE: You have to use "forward-slash" in paths, even on windows. - Wait and be patient
- Now you have a new repo at
c:\newrepo
but without the files
PS. In the "upper" repo you have to remove all changesets and re-push your new repo.
PPS. I actually wrote a blog post about this that has more details (including stripping the changesest in Bitbucket etc.
精彩评论