I have a situation where the command hg diff does not show the actual changes I made instead shows different changes. It's weird that it is happening for the file later I tried another file in the same directory it has the same issue. But other files in different directories do not have any issue.
Example -- There is a file like "test.php" where I added a new line with text "test", usually for other files when I do hg diff it will show + "test" but in this case, it shows irrelevant:
I have added only the word "test" and the rest of the things are not my changes.
All the permissions are the same and I have tried with "hg diff" and "hg diff -g" commands but have the same result. Appreciate it if anyone can help me with this.
Related
I'd like to output ("-o") the content of a file that is version controlled in mercurial. I know this can be done using the cat command.
However, the file I am interested in has been removed, so the cat command fails with a "no such file in rev X" where X was the revision number where the file was removed.
I do not wish to restore the file. How do I output the content of such a file?
One alternative to using cat would be to update to a revision where the file still existed. This would just be:
hg up -r$REV
as long as you're sure it still existed in $REV. Then you can just navigate to the file normally & view it, copy it somewhere, etc.
The usual considerations apply when doing any update - i.e., you generally need a clean working directory.
If you are using TortoiseHG, you could also use the "browse" feature to do something similar.
In THG Workbench, scroll down to the revision that still has the file. Then right click "Browse at Revision". This will show a treeview of the entire repository at that revision. You can just pick the file out of the tree and save it, etc.
hg cat -r$REV $FILE
where $REV is the revision of the file you wish to view and $FILE is the filename.
If you are unsure of the revisions you can use hg log $FILE to show you the history, so you can choose a revision before it was deleted.
Quick question:
I use Mercurial for a long term Android project and it works great. In the root level of this project, I created a file, todo.txt, which contains long term goals for my project.
For some reason, whenever I type hg status into Terminal, Mercurial always marks this todo.txt with an M for modified even when no changes were made to the file.
Anybody have a possible explanation for this harmless but bizarre occurrence?
Did you change the permissions on the file? Mercurial stores the executable bit for each file, it's possible that you changed that.
You cannot see this using the default settings, but you can if you do:
hg diff --git
The above uses the Git extended diff format.
You can also configure to use this format by default:
[diff]
git = True
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? :)
How to look at all uncommited changes to a file in hg? If we use TortoiseHG it's clear, but what about command line?
You probably want some combination of
hg status -mad to list all Modified, Added and Deleted files,
and hg diff <filename> to show the changes in a particular file.
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.