I'd like to know if it is possible to restore a removed file from an older revision (a clean way to do it)
I've renamed a file for some tests, than I commited all my work (and I forgot to rename the file) and did a lot of other commits...
When I realised, it was too late...
Regards,
Ayman
The easiest way is to simply use bzr revert with a revision number before the file was deleted:
bzr revert -rX path/to/file
bzr commit -m 'Bringing path/to/file back'
You don't need to merge anything.
If you know revision number when you removed that file (you can inspect history with bzr log -v) then you can resurrect that file with merge command. So for file foo and revision number N you need to run command:
bzr merge foo -r N..N-1
E.g. for revision 287:
bzr merge foo -r 287..286
This command will restore your file as in revision 287. You need to commit this change and you done.
This isn't the best answer. See bialix' answer which is a lot simpler. I'll leave this here just for reference.
Here's what I think is the cleanest method:
Create a branch:
bzr branch mytree repair-path
cd into the repair branch
Revert just the missing file at its last revision (eg 287 in this example):
bzr revert -r 287 lost.file
Commit the change
bzr commit -m "Unshoot my foot"
cd back into the main branch
merge in the repair
bzr merge repair-path
When ready, commit the merge and delete the repair branch.
You could do this just by reverting in the original working branch, but it's probably good practice not to. You also need to worry (just a little) about any uncommitted changes.
Related
I have a hobby project with many commits, and somewhere in the past I probably accidentally removed a file which is committed/pushed.
Is there a way to find / restore the file? (or getting the contents, it's a text file).
I don't know in which commit it has happened.
If you know the file name, you can find when it was deleted
git log --full-history -1 -- aFile
From there, knowing the commit (thanks to the previous query), you can restore it with:
git restore <commit>~ -- aFile
The ~ would take the commit parent (where the file was still there)
how to set a capistrano deployment to some particular git previous commit.
There is one command I saw cap deploy:set_current_revision
How to pass an argument to this command?
cap deploy:set_current_revision=6740ee25...` ?
How to use this command to set current revision to some previous git commit.
The deploy:set_current_revision task merely fetches the current revision from the underlying VCS.
What you would need to do is temporarily (you don't need to commit it unless you are using CI for deployments) add set :branch, '<REVID>' to your deploy.rb. Then do a normal deployment.
Sometimes I need to revert many files - near 20 - 50, but need to save the files with local changes - if I in the future will use something.
Project is big - more than 10 000 files.
Is it possible create a copy of only the files that not were committed?
Manually find changes and copy takes near 2 hours - tree of project has many nested folders.
You can create a diff with svn diff and then reapplying the diff with svn patch.
However this is not really how you should work with SVN. Better up if you can create branch with your changes, then you can later merge that branch and share the content with your peers.
Note that creating a branch is relatively cheep in SVN. On the server the files as linked to the original until actually changed. Only your changed files will take space on the server.
Note:
svn diff only saves the changed lines of your files, not the complete files. But that is enough if you need to reapply the patch.
If you really want copies of files (rather than use svn diff or do a branch), tne approach (a version of which we use for server configuration file backups) is to check which files are modified. The notes below assume you are at the top level of your repo.
For instance, if you run svn status you might get output like this:
? plans/software/intro_jan12.log
? plans/software/intro_jan12.dvi
? plans/software/data.txt
? plans/software/intro_jan12.nav
M plans/software/intro_jan12.pdf
M plans/software/jan12.tex
? plans/software/jan12/flowRoot9298.png
? plans/software/jan12/viewE_comments.pdf
? plans/software/jan12/team.ps
? plans/software/jan12/team.png
? plans/it/plan.log
(The ? shown unknown files, the M shows modified files.)
You can then easily extract modified files and do stuff with them by doing something like svn status | egrep '^M'.
Turning that into a short shell script that copies modified files elsewhere is pretty easy:
# step 1
svn status | egrep '^M' | awk '{ print $2 }' > recipe_file
# step 2
rsync -a --files-from=recipe_file <repo> <dest>
Naturally <dest> can be on a remote machine.
Presumably, once you have audited the copy files at you can then do svn revert -R.
I have a big named branch with a lot of changes. Some of these changes are non-destructive so I want to pick these specific files out first, and merge them with default as soon as possible. (Then later, the destructive changes are merged as well.)
In Git I would create another branch and squash all changesets outside of the index, then I would add the specific files to the index and commit. After that, I could merge this temporary branch with master so master has a clean commit with only the non-destructive change. I don't know how to do this with Mercurial.
You can use hg cat to grab the contents of a file as it exists on any particular branch, and replace the working copy version with that.
This isn't technically a merge, but since you're replacing whole files you shouldn't have too much of a bad time merging things later:
for example, to grab myfile.c form branch somefeature, and replace the working copy version, do:
hg cat path/to/myfile.c -r somefeature > path/to/myfile.c
note that this completely replaces the working copy file so make sure you have no outstanding changes first
I think mercurialqueues is what you want. With mq you can turn any changeset into a patch and any patch into a changeset. So taking a changeset converting it to a patch deleting the chunks out of the patch that you don't want and then applying it to whatever branch you want. This is a fairly complex operation though and requires a certain amount of discipline on your part. So I would try to nail down your workflow on a test repo before trying it on code you care about.
As far as I know, Mercurial doesnt any have tools to split changesets. If youre lucky, all the changes you want are in separate changesets and then you can use the TransplantExtension. I think it can be compared to Git's cherry-pick but I havent used git much.
You can also use hg diff to manually commit the changes to a certain file to a new branch. Use the rev range to mark your entire source branch:
hg diff myfile -r startrevision:endrevision
The output can be treated as a patch. Do this for each file you want and commit them and then merge. Skipping the destructive changes. You can also, of course, do this multiple times of a destructive change is in the middle of a revision range.
Having said that what youre trying to do isnt something mercurial was built for. That hardcore history editing is more Git's area (note that its just my opinion). Keep your stable changes and destructive changes in separate changesets (and maybe even in separate branches). I use transplant, rebase and strip to move changes around. When its all done, they are merged and properly pushed.
Oh, and check MercurialQueues. I havent used it myself but Ive seen it do some crazy stuff. Maybe its capable of doing something along the lines of what you want.
I have a file in my Clearcase repository. I checked it out and modified it, and then checked it back in.
I haven't done anything like make a baseline, or rebase, or deliver in my stream/view.
I regret having made the changes to this file--I should have undone the checkout, in retrospect.
How do I roll back the modifications? (Or undo, or revert, or whatever the correct nomenclature is.)
What is described by skwllsp can be be done in a dynamic view through the use of extended pathnames
cd m:/myDynamicView/MyVob/path/to/file
cleartool lsvtree myFile
cleartool checkout -c "cancel co" myFile
copy myFile##/main/xx myFile
cleartool checkin -nc myFile
with xx being the version number you want to restore.
But should you have made multiple checkins, including some you want to cancel, ClearCase allows you to cancel part of the previous checkins through Subtractive Merge
See IBM "to remove contributions of some versions" (and merge man page)
You can remove all changes from a range of versions at once. For example, the following command removes revisions to versions 14 through 16 on the main branch:
On the UNIX system or Linux:
cleartool merge -graphical -to opt.c -delete -version /main/14 /main/16
On the Windows system:
cleartool merge -graphical -to opt.c -delete -version \main\14 \main\16
You can also remove the changes from one version at a time. For example, the following commands remove only the changes in version 14 from the version of opt.c checked out the current view:
On the UNIX system or Linux:
cleartool merge -graphical -to opt.c -delete -version /main/14
On Windows systems:
cleartool merge -graphical -to opt.c -delete -version \main\14
Alternatively, in any of the examples above, you can leave out the -version argument if you use the version extended path for the contributor-version-selector.
Finally, the one thing to not do is a rmver.
This command destroys information irretrievably and this is rarely a good thing.
Clearcase can do much better than just making a new version where you undo the change!
Open the version history on your file, find the version you mistakenly checked in, and destroy it (select version to destroy and find the appropriate command under the Versions menu).
This is what rmver does too, if you want to use the command line.
As VonC said your this destroys your mistake irretrievably. I'm not seeing a downside to that.
Open version history for this file, then open in your editor a proper version of the file from the version tree, check out file once more, replace its with content of the previous correct version and check in. Don't forget to compare the previous version and the last version.
cleartool unco #filename should do the job for you.
But if the version in the main branch/ branch from where your branch is created, goes forward with versions, when you undo your checkout, the new version is acquired instead of the version from which you branched.