hg rollback was the easy way to simply undo your last local Mercurial repository transaction.
Sadly hg rollback has been deprecated as of Hg2.7 August 2013
Most of the question/answers are seeking solution to undo "Write nature" commands easily doable with strip or other "Delete nature" commands.
But what happens with delete related commands?
I rebased and Collapsed a set of commits (all from the same branch) into one.
Now how do i undo this action???
I suggest to look into both: mercurial phases and the evolve extension of mercurial. Using the either secret or draft phase as your default phase you then can easily undo anything you did not yet push (which usually makes them public, thus immutable) as old changesets are kept as obsolete changesets which you can revive if needed.
The old, pre-squashed commits may be there -- just hidden (depending exactly how your collapse command works).
Step one is the find the hashes that you care about. I use the smartlog extension, so this is 'hg sl --hidden --all', but some form of 'hg --hidden log' should work for you too. If you are lucky enough to still have a screenshot with the expected hashes that's better.
Step two is to recover those commits. I did it by attaching a bookmark to each of the commits I wanted back.
Related
I am using git on VS2019
I was wondering if there is a way to remove old commits but always keep the latest code. The reason is that when I work on a big change, I do a lot of commits after checking every small step but at the end it is annoying when I click on view history and need to search an old commit to compare the changes. I would like to remove specific commits but leave the changes. In that way I will see on history only the main milestones of the developing process. There is a way to do that??
It sounds like in these scenarios, you're developing a new feature, in which case you should be using a branch+pull request approach to development. During the pull request, you can do a squash merge. It's not all in the command line, but that might be for the best anyway.
If you're already working within a feature branch, then I like VonC's approach.
It seems that you want the git rebase feature.
If you know how many commits you want to squash together, you can use
git rebase -i HEAD~N
You can also do it in interactive mode:
git rebase --interactive HEAD~N
Be aware that if you merging commits you have already pushed, you may have trouble with your next push.
For more details, see: https://www.internalpointers.com/post/squash-commits-into-one-git
You can follow a workflow similar to "Git better with fixups " from Atul Sharma
For the commits which are incremental improvement for the same step, use git commit --fixup small step, which allows you to "do a lot of commits after checking every small step".
(You can see it in Git Extension in Visual Studio)
But at the end, you can cleanup all those small steps with git rebase --interactive --autosquash <First step commit> (assuming you have not pushed those commits yet)
That way, you end up with a cleaner history.
I am new to SVN , we are using SVN version controller in eclipse (Lunar), We have a module,that module code's may go to Release or may not go to release depends on the business approval, is there any way in SVN to commit/rollback set of changes(different File changes) on single action ?
Thanks & Regards
S.Sathiya
To roll back changes in Subversion while maintaining the history of all events, you need to perform what's known as a reverse merge. You're essentially applying a patch which reverses the changes that were done between "now" and the state you want to roll back to.
You can apply a reverse merge to a whole tree/subtree, or individual elements (files/directories). To make things easy, work in the largest chunks you can manage.
Simply check out the version of the file you would like to have and commit it to the repo. Reverting is a feature to undo accidental whole commits (so it would have an effect on other files too, which is probably undesired). If the whole thing you want to undo is a complete commit, then yes, reverting under the Team context menu or in the history is what you are searching for.
I have an open source project on bitbucket. Recently, I've been working on an experimental branch which I (for whatever reason) didn't make an actual branch for. Instead what I did was use bookmarks.
So I made two bookmarks at the same revision
test --the new code I worked on that should now be abandoned(due to an experiment failure)
main -- the stable old code that works
I worked in test. I also pushed from test to my server, which ended up switching the tip tag to the new unstable code, when I really would've rather it stayed at main. I "switched" back to the main bookmark by doing a hg update main and then committing an insignificant change. So, I pushed this with hg push -f and now my source control is "correct" on the server.
I know that there should be a cleaner way to "switch" branches. What should I do in the future for this kind of operation?
tip is not a widely useful concept in a repository which has branches of any kind. Whether you are using bookmarks, named branches, or anonymous branches, tip always means the most recent commit on any branch, which is rarely something you care about. The real solution to your problem is to stop worrying about the tip!
I don't really understand your question, since you are switching (without quotes) branches, even if they are not named branches, they are still branches when you use bookmarks.
The mistake you had was an honest mistake and I see no way of having Mercurial protect you from doing that again with bookmarks (marking the same rev with different bookmarks and committing with the wrong one). What I can tell you though is how to do private local branching with Mercurial, and this way you can avoid having the consequences you just had:
You use named branches and phases
Mercurial Phases are really sweet, let me explain them real quick. You can mark revisions to three special states called phases, and these are: secret, draft and public.
secret: Don't get pushed. Can be modified through history editing.
draft: Get pushed. Can be modified through history editing. This is the default state of any revision.
public: Get pushed. Will issue a warning when using history editting extensions on them (strip, rebase, histedit,...).
As mentioned, all local revisions are draft by default, when you push them, they become public. You can use the hg phase command to mark revisions to a particular phase, but if you are going from #3 to #2, or from #2 to #1 (according to the previous numbering), you need the -f argument to force the change, this is:
secret --> draft --> public
To go to the left you need to use --force or -f.
Here is what you do:
hg branch experiment
hg commit -m "Opening experimental branch" //say this creates revision 123
hg phase -sf tip //s is for secret, f is for force
//... hack hack hack
hg commit -m "Uh oh screwed up here"
hg push //no secret revisions are pushed
Now, you can just abandon that branch and leave it like so, it wont ever get pushed. Forget about it and even just close it so that it wont bother you when you list your branches. It won't get pushed it won't get listed, so just don't worry about it.
However, if you have OCD, just strip (hg strip) the branch at the commit where the branch was opened, and it is gone:
hg strip 123
If you have an already existing branch, you can phase several revisions at once like this:
hg phase <start revision>::<end revision> -sf
To make your secret branch draft or public, just phase the latest revision to those phases:
hg phase -d tip //assuming you are in the experiment branch
Then push, and the branch will become public.
Mercurial has been increasingly becoming better at history modification without changing it's general philosophy of discouraging just that. Phases are meant to protect you from accidental history modification as well as from sharing what you don't mean to.
How *I* use bookmarks
Personally, I use bookmarks for debugging and for when I want to try 2 different ways of doing one thing. To me, bookmarks are useful when you want to do anonymous branches (update to a previous revision, commit and fork the history) but want to keep things intelligible.
I'm fairly new to Mercurial, but one of the advantages I see using Mercurial is that while writing a feature you can be more free to experiment, check in changes, share them, etc, while still maintaining a "clean" repo for the finished feature.
The issue is one of history. If I tried 6 different ways to get something to work, now I'm stuck with all of the history for all my mistakes. What I'd like to do is go through and clean up my changes and "collapse" them into one changeset that can be pushed into a shared repository. This is complicated by the fact that I might pull in new changesets from the shared repository, and have those changesets intermingled with my own.
The best way I know of to do that is to use hg export to create a patch of my changes since cloning, clone a fresh repository, and apply the patch to the fresh repository.
Those steps seems a little bit cumbersome and easy to mess up, particularly if this methodology is rolled out to the whole dev team, some of whom are a little resistant to change (don't get me started). TortoiseHg makes the process slightly better since you can highlight the changesets you want to be included in an export.
My question is this: Am I making this more complex than it needs to be? Is there a better workflow I can use to ease my troubles? Is it too much to expect a clean history where entire (small-ish) features are included in one changeset?
Or maybe my whole question could be summed up this way:
Is there an equivalent for this in mercurial? Collapsing a git repository's history
Although I think you should reconsider your use of branches in Mercurial (as per my comment on your post), using named branches doesn't really help with your concern of maintaining useless or unnecessary history - it just organizes them a bit.
I would recommend a combination of these tools:
mercurial queues
histedit (not distributed with Hg)
the mq changeset strip feature
to rework a messy history before pushing to a blessed or master repo. The easiest thing would be to use strip to permanently remove any changeset with no children. Once you've done that you can use mq or histedit to combine, relocate, or modify existing commits. Histedit will even let you redo the comment associated with a changeset.
Some pitfalls:
In your opening paragraph you mention sharing changesets during feature development. Please understand that once you've shared a changeset it's not a good idea to modify using mq or histedit, or strip. Using these extensions can result in a change to the revision hash, which will make them look like a new changeset to everyone else.
Also, I agree with Paul Nathan's comment that mq (and histedit) are power features and can easily destroy a history. It's a good idea to make a safety clone before using these extensions.
Named branches are the simplest solution. Each experimental approach gets its own branch.This retains the history of the experiments.
The next solution is to have a fresh clone for each experiment. The working one gets pushed back to the main repo.
The next solution - and probably what you are really looking for - is the mq extension, which can "squash" a series of patches into a single commit. I consider mq to be "advanced", and "subject to accidently shooting yourself in the foot". I also don't care to squash my commits - I like having my version history present for reference.
A developer in my team has been using a branch bound to the server (IE, only using checkout, update, and commit), but also often uses the --local flag on commit and then commits to the server in a batch. She recently experienced a situation where she is missing some local commits, and can't find them in the repo OR her local code. She suspects that this is because she did a pull at some point in bettween local commits and server commits.
Neither of us are particularly experience with Bazaar -- What may have happened, and where can we look for this missing code? She is fairly certain that she never did anything destructive, and I am fairly certain that Bazaar would have asked her if it was going to do that. I vaguely remember that Bazaar has some notion of "hidden" repos/trees/whatever where it puts things before changing a bunch of code, from which someone might recover lost code, but I can't manage to google for what that is.
I figured out that the "'hidden' repos/trees/whatever" that I was referring to are "dead heads", viewed with bzr heads.
We found our dead head and merged it back in -- code saved!
$ bzr heads
$ # output shows various heads, with names like: revision-id: john#mycomputer-20100630175358-39qro1z5qdq2o9ay(dead)
$ bzr merge john#mycomputer-20100630175358-39qro1z5qdq2o9ay
If all else fails, you can try asking in the bazaar IRC channel.
Go there now* and wander into the #bzr channel. There are usually people there and they are usually helpful.
**That's freenode's web interface. If you haven't used IRC before, you make up your own nickname, choose the #bzr channel, and no need to auth (as long as your nickname is unique).*
At any time you can do a
bzr status
and this will should you if there are any uncommitted changes, including merges that have not been committed. This may help in determining where everything is at. If you do a merge and you haven't followed it up with a commit (whether or not there were conflicts) then the result of the merge will remain uncommitted.
Doing a bzr pull shouldn't have wiped out any work - as I understand it, it should just fail if the local branch has uncommitted changes.