Mercurial - how to retrieve orig file after a revert? - version-control

I accidentally ran hg revert and lost all changes to my file foo.js. I see that a backup of the file exists as foo.js.orig. How can I add the orig file back so that I can reinstate my changes?
Update: I used hg add foo.js.orig to add the file back, but how can I replace the existing foo.js file with the original foo.js.orig file? I am new to mercurial so any help appreciated, thanks!

I solved this by:
Adding the file back using hg add foo.js.orig
Renaming the file using hg rename -f foo.js.orig foo.js (this replaces the existing-but-outdated foo.js file)

You should just remove (or rename) foo.js and then rename foo.js.orig to foo.js. Then you can commit as normal.
foo.js.orig is not a tracked file in source control, and never needs to be.

Related

.gitignore file not ignoring .env.local or any other supposed private file

I encountered this error because I once mistakenly committed .env.local before adding it to .gitignore. The answer to it below.
If you're facing something similar and you use the Git GUI in VSCode, just follow these steps:
Open your .env.local file or any file that's having this issue, copy the content to clipboard, and delete the file entirely.
Open your .gitignore file and delete the line that removes that file.
Commit your changes (not necessarily publish).
Now create a new .env.local file (or the file you deleted earlier in your case.)
Switch to your Source Control tab (where you see staged files), right click on this newly created file and add it to .gitignore
Now, it will be ignored for real.

Revert local changes in fossil

How do I clean/revert/undo local, un-commited changes in a single source file with Fossil?
The clean command looks to me like it should do the trick, but no, the local changes are still there. I am looking for the same effect as "git checkout filename.c" would have.
fossil revert <filename>
.
>fossil help revert
Usage: fossil revert ?-r REVISION? ?FILE ...?
Revert to the current repository version of FILE, or to
the version associated with baseline REVISION if the -r flag
appears.
If FILE was part of a rename operation, both the original file
and the renamed file are reverted.
Revert all files if no file name is provided.
If a file is reverted accidently, it can be restored using
the "fossil undo" command.
Options:
-r REVISION revert given FILE(s) back to given REVISION
See also: redo, undo, update

Replace local file by remote file

How do I replace a local file by its latest version in the repository?
Is there also a way of replacing all local files which are conflicting with the corresponding files from the repository?
Both hg update -C and hg revert will do what you are looking for - replace a locally modified file with the clean version in the repository. Personally I prefer hg revert but hg up -C will also do the job
hg revert
Some further details from the help for hg revert
With no revision specified, revert the specified files or directories to
the contents they had in the parent of the working directory. This
restores the contents of files to an unmodified state and unschedules
adds, removes, copies, and renames. If the working directory has two
parents, you must explicitly specify a revision.
Using the -r/--rev or -d/--date options, revert the given files or
directories to their states as of a specific revision. Because revert does
not change the working directory parents, this will cause these files to
appear modified. This can be helpful to "back out" some or all of an
earlier change. See "hg backout" for a related method.
Modified files are saved with a .orig suffix before reverting. To disable
these backups, use --no-backup.
Hope that helps
Chris
svn update ?
Or delete your folder, and svn checkout...
Or try the option --force.

How to remove files of specific type in mercurial?

I created .hgignore file. But forgot about .db files. So after hg add this files were added to be tracked. I found the remove command but can not figure out how to remove all the .db with a single command
Found it myself:
hg forget "glob:**.db"
This works:
hg forget -I '**.db'
Don't forget to hg commit that change.

What is the difference between hg forget and hg remove?

I want mercurial to remove several files from the current state of the repository. However, I want the files to exist in prior history.
How do forget and remove differ, and can they do what I want?
'hg forget' is just shorthand for 'hg remove -Af'. From the 'hg remove' help:
...and -Af can be used to remove files
from the next revision without
deleting them from the working
directory.
Bottom line: 'remove' deletes the file from your working copy on disk (unless you uses -Af) and 'forget' doesn't.
The best way to put is that hg forget is identical to hg remove except that it leaves the files behind in your working copy. The files are left behind as untracked files and can now optionally be ignored with a pattern in .hgignore.
In other words, I cannot tell if you used hg forget or hg remove when I pull from you. A file that you ran hg forget on will be deleted when I update to that changeset — just as if you had used hg remove instead.
From the documentation, you can apparently use either command to keep the file in the project history. Looks like you want remove, since it also deletes the file from the working directory.
From the Mercurial book at http://hgbook.red-bean.com/read/:
Removing a file does not affect its
history. It is important to
understand that removing a file has
only two effects. It removes the
current version of the file from the
working directory. It stops Mercurial
from tracking changes to the file,
from the time of the next commit.
Removing a file does not in any way
alter the history of the file.
The man page hg(1) says this about forget:
Mark the specified files so they will
no longer be tracked after the next
commit. This only removes files from
the current branch, not from the
entire project history, and it does
not delete them from the working
directory.
And this about remove:
Schedule the indicated files for
removal from the repository. This
only removes files from the current
branch, not from the entire project
history.
If you use "hg remove b" against a file with "A" status, which means it has been added but not commited, Mercurial will respond:
not removing b: file has been marked for add (use forget to undo)
This response is a very clear explication of the difference between remove and forget.
My understanding is that "hg forget" is for undoing an added but not committed file so that it is not tracked by version control; while "hg remove" is for taking out a committed file from version control.
This thread has a example for using hg remove against files of 7 different types of status.
A file can be tracked or not, you use hg add to track a file and
hg remove or hg forget to un-track it. Using hg remove without
flags will both delete the file and un-track it, hg forget will
simply un-track it without deleting it.