Say if we have a project known as main
, and then we have a project that is analytics
, and in Bash, we are at the analytics
work开发者_StackOverflow社区ing directory and accidentally push to the main
remote repository, will all the files in analytics
be added to the main
project, and is it reversible?
You will get a complaint from Mercurial and the push will be aborted. It looks like this:
# create main repo:
% hg init main
% touch main/a.txt
% hg -R main commit --addremove -m main
adding a.txt
# create analytics repo
% hg init analytics
% touch analytics/a.txt
% hg -R analytics commit --addremove -m analytics
adding a.txt
# try the push:
% hg -R analytics push main
pushing to main
searching for changes
abort: repository is unrelated
Mercurial knows if two repositories are related based on their root nodes. That is, repositories A and B are related if they share a common root node.
if main
is a local repository, you can navigate to main
and perform a histedit to drop the offending commits. You can histedit from a server-based main
as well, but if any other users have created clones, when they push to main they will re-add the changes.
histedit is an Hg extension that doesn't come bundled with Hg. Once you install it you can use it like this:
> hg histedit <rev>
where is the start of the offending commits. Histedit will generate a list of commits from up to the tip. In this list you can indicate to histedit that you want to keep the commit, edit the comment, or drop the commit. Drop should do the trick.
精彩评论