Mercurial: How to restore file names removed with "hg rm -A"? - version-control

Okay, so I really got ahead of myself here.
After moving a number of files around, renaming some, and deleting a bunch more, I ended up with a large number of files in hg status with an exclamation point (along with numerous question marks). I ran hg rm -A to remove all the files that no longer existed.
Then I realized I should have used hg addremove to track the files that were just moved, not deleted. Oops.
But I hadn't committed anything yet, and hg status showed all those "missing" files with an R now. So I ran hg revert thinking that would restore everything to the way it was. I could even see where it said Undeleting file /path/to/xyz for each file that I wanted to restore (I wasn't worried about restoring the files themselves, of course, just the file paths).
But instead of a big list of files with exclamation points, those "removed" file references are simply gone. They're not listed in hg status, they're not in the file system (obviously), and they're not listed in any recent commit.
What's going on here?
Why would all those file references just disappear from the repo without a commit?
How can I get those file references back so I can actually track them like I wanted to?
I'm pretty rusty with DVCS, I guess. I realize now I should have been using hg move for these operations, but that doesn't help my current situation, does it? :)

Related

git rm -f after add, before commit, on windows cmd line. Was open earlier in STS (Eclipse). Can recover?

I wanted to unstage files (as my .gitignore was not set up to ignore some of my IDE files) but in hurry did :
git add w3
//got some .settings etc folder and files added, in newly added sub folder w3
//the repo here already had sub folders w1 & w2.
Then issued:
git rm -f w3/*
I'm on windows 8. The files are hard deleted (not in the recycle bin). Any thing I can do with git or any other (free) way?
Edit Add
* Also it was opened in STS(eclipse) but now deleted the pom, settings everything. Anyway to restore from within eclipse?
Un-commited but added files are still in a repository for a while, however it would be quite tricky to restore it especially for a large old repository as usually it has a lot of garbage. So, if you don't mind dig into garbage, start with git fsck and look for dangling blob.
However, seems you cannot restore names of lost files, only content.
If the file was not versioned you can't restore it. See the documentation of git-rm. See here for how to undo adding a file to the staging area.
If the file was versioned you can retrieve it from a past commit. See this answer for more information.
Of course if you back up your drive you might be able to restore it with your back up program. For that you might get help over at SuperUser.

how to "propertly" not commit changes on mercurial?

Accidentally i hg added several binary compiled files from a project along with tons of little changes on several files.
my hg status now show that i have a dozen files modified (correctly) and two dozen files added (mistake).
how do i undo that?
Most answers here tell me to install the MQ extension or to use rollback, but the manual for MQ ext says that i'm not really supposed to use it and that there are (slightly more complicated) ways of doing the same MQ does with mainline hg -- though it fails to show how. and rollback shows warnings about not being supposed to be used because it is deprecated.
So, how do i remove from my upcoming commit the files added by mistake, while keeping the modified files that i want to commit?
When you added (instead of modified) the files accidentially use hg forget FILENAME instead of hg revert FILENAME.
You can revert those files. hg revert fileyouwanttorevert otherfileyouwanttorevert

Deleting tracked file from the file system vs hg remove

I'd like to know if there are any consequences when deleting a tracked file from file system (e.g. via windows explorer) in comparison with when using hg remove to delete it from file system and untrack it.
In both cases, I'll commit afterwards, just in the first case tortoise HG marks the file as missing with exclamation mark, with the second it marks it as clean and ready for removal.
Besides this are there any differences?
If you go the file system path and don't make any other changes to tracked files, hg will give you an error when you try to commit:
nothing changed (1 missing files, see 'hg status')
(This is just a special case of nothing changed.)
If you have changed something else, hg won't complain at that point, but the file's status will continue to show up as missing with hg status. This has the negative effect of cluttering up your (mental) workspace and making it harder to tell at a glance what your working directory's current status is. Moreover, the file remains in the repository and will be restored by hg update for any revisions where it is still being tracked!
hg remove will return an error if the file was already deleted from the filesystem; in this case you should use hg forget to tell Mercurial to stop tracking the file.
If you prefer doing big changes with external utilities (like Windows Explorer), you can use the nifty hg addremove which automatically detects additions and removals. (The downside is that you might remove and untrack accidentally deleted files.)

Git with Xcode, no such file or directory

I've been searching around and looking for answers but I haven't found something that works yet. I apologize if this is easy and someone has already answered this as I'm new to Git.
What happened was there was a branch both my coworker and I were using. There was a conflict when I tried to commit (I honestly can't remember if it was committing or when I Pulled in her changes). Basically we were both deleting unused files, images, etc. I went through the conflicts and I thought I went through it properly accepting both of our changes, but something still might have gotten messed up because I'm getting
No such file or directory
For a specific image. These are some of the things I tried, with cleaning and rebuilding after I have tried one of these which have not worked.
- Adding the image back to the project (Xcode still thinks its missing and doesn't update it's .xcodeproj)
- git reset HEAD <file>
- git add <file>
Nothing seemed to work. When I try git status, I saw that it is an untracked file. I then removed it. I see my .xcodeproj is
$10 says the .xcodeproj doesn't recognize the existence of the image. Git does a very poor job of properly merging the .xcodeproj file, and you will often have to readd files due to a bad merge.
When in doubt, find a past version of your .xcodeproj that works, bring it to your master HEAD, and add the files that are missing from the .xcodeproj.

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.