I'm frequently reviewing our commits since we last merged our dev branch to default (ie, we released a version) and so I want to list the commits since that merge in mercurial. Right now, I am using the date and am using log + grep and a date.
ex:
hg log -r "date('>2017-03-02')"
Is there a way to do this from a commit? Or should I just keep grabbing the date/datetime off the commit for the merge to default and doing what I'm doing?
All revisions in a branch starting with changeset XXX:
hg log -rXXX::
All revision in the whole repo starting with changeset XXX:
hg log -rXXX:
It's even mentioned on the first page of hg help revsets:
- Changesets between tags 1.3 and 1.5 mentioning "bug" that affect
"hgext/*":
hg log -r "1.3::1.5 and keyword(bug) and file('hgext/*')"
Related
Given a checkout of a Mercurial repository and a filename. How does one determine the last commit that changed that file? Unlike git, care must be taken with branches. The intended semantic here is to follow the history of the branch. Where branches fork from other branches, follow parent branches.
Non-solutions:
shows commits from unmerged branches
hg log -l 1 filename
empty output if the file remains unchanged after branch creation
hg log -l 1 -b . filename
Arguably, this question highlights misuse of branches and bookmarks should be used instead. However that may be, existing history necessiates taking branches into account.
The -f flag tells hg log to follow history of the current or selected changeset, so this should find the first change of a file without looking at changesets that aren't direct ancestors:
hg log -f -l 1 filename
I have a mercurial repo with the following history (most recent commit at the top) on a feature branch:
mergeDefaultA
|
mergeDefaultB
|
C
|
mergeDefaultD
mergeDefaultXXXX are merge commits that came as the result of merging the default branch into the feature branch.
What has happened is commit C is screwed, but this was not noticed until after I had pushed mergeDefaultA to Bitbucket. What I want is the following picture:
exactlyWhatIsInMergeDefaultD
|
mergeDefaultA
|
mergeDefaultB
|
C
|
mergeDefaultD
Where exactlyWhatIsInMergeDefaultD is literally exactly what was the state of the code in mergeDefaultD. However, everything I'm reading seems to indicate either you can't undo a series of commits like this (only a single commit back) and even then many of the options aren't available once you've pushed "into the wild".
How do I achieve this?
If this was git, I'd do:
git revert mergeDefaultD
How do I do the same in Mercurial?
Here's what I think you want:
hg revert -r GOOD_REVISION_NUMBER --all
hg commit -A -m "reverting back to revision GOOD_REVISION_NUMBER"
Once that is committed, as soon as someone pulls from you (or you push to them) they will get the most recent revision containing only the good stuff. If they ever do want to go back to the bad stuff, you could always update to that revision:
hg update -r BAD_REVISION_NUMBER
To expand a bit on Harvtronix' answer (which is fine, by the way):
One simple way is to revert to the old revision number ('GOOD') and commit. Note: reverting means that you set the files to the same content as in revision 'GOOD', you don't go back down the tree to that commit. If you did, you would indeed branch off and have two heads.
hg revert -r GOOD --all
hg commit -m "all is good now"
Another way can be to only throw out revision C (if I read your explanation correctly, it's actually just C that is causing the issue). 'hg backout'will introduce the reverse of C in your working directory, so you can then commit it.
hg backout -r C
hg commit -m "Backed out C"
Finally, one last option is to close the bad branch, update to the last commit that was fine and commit further there:
hg up -r BAD
hg commit --close-branch -m "This head is bad"
hg up -r GOOD
... continue here ...
I have some issue with Mercurial. The checkout of a revision is working (via hg clone -r X command, which clones the X. revision), but when i tried to get log for the X. revision, it returns with revision not exist. How can i solve this problem?
Commands i use:
hg clone -r RevisionNumber /path/to/local/repo my_folder
Then:
hg log -r RevisionNumber --template 'my_template'
hg diff -c RevisionNumber
I get:
abort: unknown revision 'RevisionNumber '!
I tried revisioning with number, and with number:hash, neither worked.
My guess here is that you are referencing the changeset by the revision id (your RevisionNumber) that is local to the original repo. Only the changeset identifying hash is globally unique. I'm basing this guess on your statement
I tried revisioning with number, and with number:hash, neither worked.
You should try using only the hash and see if that works.
hg log -r [hash]
(If you do number:hash, hg thinks your are looking for the range of changes between number and hash.)
Explanation: When you clone to a specific revison, Mercurial only includes changesets that direct ancestors of that revision and leaves out all others. The numbering is locally sequential (meaning new numbers are assigned as the changeset arrives at the repo).
I have a mercurial repo with no uncommitted changes. I was on revision 846, and decided my last 2 commits were junk and wanted to carry on as if from revision 844. So I was going to type:
hg revert -r 844 --all
Unfortunately I mistyped, and wrote:
hg revert -r 44 --all
So my whole repository has changed dramatically, including directory structure. I don't see any .orig files, so I don't think the answer in:
How to undo a revert in mercurial
helps me.
hg log still has all of my commits up to revision 846 - do you think I can revert back to revision 846?
Advice very welcome
hg revert just sets your working copy to the revision that you specify so if you didn't do a commit after the revert then your repository has not changed. To fix it you can just do hg update -C and then delete all the .orig files.
After that you can do the correct revert statement to remove the last two revisions.
If you did do the commit then the command that you wanted to do (hg revert -r 844 --all) would still get you to the point that you want by undoing the revert commit as well as the two commits that you originally intended to undo.
I made a change a few months ago in a file in the default branch. Today we discovered that change somehow got merged into another branch. When I run hg log against that file, I'm only seeing the original changeset. I'm not seeing how that changeset made it into the branch.
What revset query can I pass to hg log to trace a changeset as it gets merged between branches?
If the changeset in question lives on a named branch, you can use hg log -r 'descendants(<the_rev>) and branch(default)', and the first changeset shown should be the merge.