Mercurial: Get non-versioned copy of an earlier version of a file - version-control

How do I get a non-versioned copy of an older version of a file from a mercurial repository?
Edit: I have changed somefile.png (binary file) in my local copy. I am looking for a command which will allow me to get an earlier version of somefile.png so that I can compare it with my modified copy (using an image viewer) before I commit changes. How can I do that?

The command you are looking for is cat
hg cat [OPTION]... FILE...
output the current or given revision of files
hg cat -o outputfile.png -r revision somefile.png
You can then compare somefile.png with outputfile.png

If you mean: what is the equivalent of svn export?, that would be:
hg archive ..\project.export
See also this TipsAndTrick section
Make a clean copy of a source tree, like CVS export
hg clone source export
rm -rf export/.hg
or using the archive command
cd source
hg archive ../export
The same thing, but for a tagged release:
hg clone --noupdate source export-tagged
cd export-tagged
hg update mytag
rm -rf .hg
or using the archive command
cd source
hg archive -r mytag ../export-tagged

There's a tip on the hgtip that might get you most of the way there:
Merging binary files
While it specifically talks about merging, the diff stuff should be generic enough to do it outside a merge...

I'm not sure I understand the question. You you could just copy it somewhere else using the normal file copy tools of your operating system.

Related

How can I ignore any changes in a particular folder from Git

I want to exclude the changes in all files in a folder Api\Bin*.* and Core\obj*.* into GitHub merging. I dont want to consider that folder while merging the changes. How can I do that Please advise. I have added the following line of code in ignored file from Repository->Setting->Ignored files , but not working . When compile the program , still obj and bin folder files is showed in changes of GitHub
You can add a line in gitingore files following ways
logs/
These lines will ignore the logs folder. Even you can use patterns.
If those files are already tracked, no amount of .gitignore would work.
You need to remove them first (from the Git index, not from your disk)
git rm --cached -r API/bin/
git rm --cached -r Core/obj/
Then check (no commit needed) if you see them in GitHub Desktop.
You can also see if your .gitignore rules apply with:
git check-ignore -v -- Core/obj/<anObjFile>

Cocoapods gitignore not working in swift3 xcode project [duplicate]

This question already has answers here:
How do I make Git forget about a file that was tracked, but is now in .gitignore?
(33 answers)
Closed 5 years ago.
I have an already initialized Git repository that I added a .gitignore file to. How can I refresh the file index so the files I want ignored get ignored?
To untrack a single file that has already been added/initialized to your repository, i.e., stop tracking the file but not delete it from your system use: git rm --cached filename
To untrack every file that is now in your .gitignore:
First commit any outstanding code changes, and then, run this command:
git rm -r --cached .
This removes any changed files from the index(staging area), then just run:
git add .
Commit it:
git commit -m ".gitignore is now working"
To undo git rm --cached filename, use git add filename.
Make sure to commit all your important changes before running git add .
Otherwise, you will lose any changes to other files.
Please be careful, when you push this to a repository and pull from somewhere else into a state where those files are still tracked, the files will be DELETED
If you are trying to ignore changes to a file that's already tracked in the repository (e.g. a dev.properties file that you would need to change for your local environment but you would never want to check in these changes) than what you want to do is:
git update-index --assume-unchanged <file>
If you wanna start tracking changes again
git update-index --no-assume-unchanged <file>
See git-update-index(1) Manual Page.
Also have a look at the skip-worktree and no-skip-worktree options for update-index if you need this to persist past a git-reset (via)
Update:
Since people have been asking, here's a convenient (and updated since commented on below) alias for seeing which files are currently "ignored" (--assume-unchanged) in your local workspace
$ git config --global alias.ignored = !git ls-files -v | grep "^[[:lower:]]"
To untrack a file that has already been added/initialized to your repository, ie stop tracking the file but not delete it from your system use: git rm --cached filename
Yes - .gitignore system only ignores files not currently under version control from git.
I.e. if you've already added a file called test.txt using git-add, then adding test.txt to .gitignore will still cause changes to test.txt to be tracked.
You would have to git rm test.txt first and commit that change. Only then will changes to test.txt be ignored.
Remove trailing whitespace in .gitignore
Also, make sure you have no trailing whitespace in your .gitignore. I got to this question because I was searching for an answer, then I had a funny feeling I should open the editor instead of just cat'ing .gitignore. Removed a single extra space from the end and poof it works now :)
i followed these steps
git rm -r --cached .
git add .
git reset HEAD
after that, git delete all files (*.swp in my case) that should be ignoring.
Complex answers everywhere!
Just use the following
git rm -r --cached .
It will remove the files you are trying to ignore from the origin and not from the master on your computer!
After that just commit and push!
If you want to stop tracking file without deleting the file from your local system, which I prefer for ignoring config/database.yml file. Simply try:
git rm --cached config/database.yml
# this will delete your file from git history but not from your local system.
now, add this file to .gitignore file and commit the changes. And from now on, any changes made to config/database.yml will not get tracked by git.
$ echo config/database.yml >> .gitignore
Thanks
To remove just a few specific files from being tracked:
git update-index --assume-unchanged path/to/file
If ever you want to start tracking it again:
git update-index --no-assume-unchanged path/to/file
As dav_i says, in order to keep the file in repo and yet removing it from changes without creating an extra commit you can use:
git update-index --assume-unchanged filename
None of the answers worked for me.
Instead:
Move the file out of the git-controlled directory
Check the removal into git
Move the file back into the git-controlled directory
After moving the file back, git will ignore it.
Works with directories too!
Not knowing quite what the 'answer' command did, I ran it, much to my dismay. It recursively removes every file from your git repo.
Stackoverflow to the rescue... How to revert a "git rm -r ."?
git reset HEAD
Did the trick, since I had uncommitted local files that I didn't want to overwrite.
There is another suggestion maybe for the slow guys like me =) Put the .gitignore file into your repository root not in .git folder. Cheers!
If the files are already in version control you need to remove them manually.
another problem I had was I placed an inline comment.
tmp/* # ignore my tmp folder (this doesn't work)
this works
# ignore my tmp folder
tmp/
Thanks to your answer, I was able to write this little one-liner to improve it. I ran it on my .gitignore and repo, and had no issues, but if anybody sees any glaring problems, please comment. This should git rm -r --cached from .gitignore:
cat $(git rev-parse --show-toplevel)/.gitIgnore | sed "s/\/$//" | grep -v "^#" | xargs -L 1 -I {} find $(git rev-parse --show-toplevel) -name "{}" | xargs -L 1 git rm -r --cached
Note that you'll get a lot of fatal: pathspec '<pathspec>' did not match any files. That's just for the files which haven't been modified.
I have found a weird problem with .gitignore. Everything was in place and seemed correct. The only reason why my .gitignore was "ignored" was, that the line-ending was in Mac-Format (\r). So after saving the file with the correct line-ending (in vi using :set ff=unix) everything worked like a charm!
One other problem not mentioned here is if you've created your .gitignore in Windows notepad it can look like gibberish on other platforms as I found out. The key is to make sure you the encoding is set to ANSI in notepad, (or make the file on linux as I did).
From my answer here: https://stackoverflow.com/a/11451916/406592
If you need to stop tracking a lot of ignored files, you can combine some commands:
git ls-files -i --exclude-standard | xargs -L1 git rm --cached
This would stop tracking the ignored files. If you want to actually remove files from filesystem, do not use the --cached option. You can also specify a folder to limit the search, such as:
git ls-files -i --exclude-standard -- ${FOLDER} | xargs -L1 git rm
On my server linux server (not true on my local dev mac), directories are ignored as long as I don't add an asterisk:
www/archives/*
I don't know why but it made me loose a couple of hours, so I wanted to share...
One thing to also keep in mind if .gitignore does not seem to be ignoring untracked files is that you should not have comments on the same line as the ignores. So this is okay
# ignore all foo.txt, foo.markdown, foo.dat, etc.
foo*
But this will not work:
foo* # ignore all foo.txt, foo.markdown, foo.dat, etc.
.gitignore interprets the latter case as "ignore files named "foo* # ignore all foo.txt, foo.markdown, foo.dat, etc.", which, of course, you don't have.

restore.dg is not fitlered by .gitignore

In my newest .NET Core ASP.MVC project I seem to be unable to ignore the restore.dg file. By default, the Visual Studio .gitignore file is set to ignore the whole .vs/ folder, in which the file is located. As this did not work, I tried several methods how to get rid of the file, yet unsuccessfully.
# Visual Studio 2015 cache/options directory
.vs/
restore.dg
*.dg
.vs/*
Could somebody help me?
Remove it from the cache.
git rm --cached .vs/restore.dg
git commit -m "Remove restore.dg from the cache"
See also: How to make Git "forget" about a file that was tracked but is now in .gitignore?
This might happen after you have already committed this file into the repository. If this is the case you have to remove it using git rm --cached <filename> command and commit this change to the repository. After that it will disappear from git status and will never bother you again.

Get latest revision number of a file from cvs repository

Is there a way to know the latest revision number of a file in cvs repository without checking out that file.
The exact problem is, suppose I know the name of a file which is in cvs repo. Let's call it file1.text.
So, is there any command or any way by which I can search repo for that file and get the latest revision number of that file?
You can use CVS log and give a revision as "starting point":
$ cvs log -r{REVISION}:: file1.text
The -r{REVISION}:: will only search for revisions after {REVISION} (can be a number or tag).
If you don't have a working copy, you can use rls cvs command. With -l argument, it will print the version of files.
$ cvs rls -l MyModule/path/to/the/file
You can use -r to specify a branch.
Here's the command to use:
cvs history -a -c -l module/file1.text
This will display the version and the date the file was last modified. This doesn't require the module or file checked out.

Retrieve old version of a file without changing working copy parent

How do you get a copy of an earlier revision of a file in Mercurial without making that the new default working copy of the file in your workspace?
I've found the hg revert command and I think it does what I want but I'm not sure.
I need to get a copy of an earlier revision of my code to work with for a few minutes. But I don't want to disturb the current version which is working fine.
So I was going to do this:
hg revert -r 10 myfile.pls
Is there a way to output it to a different directory so my current working version of the file is not disturbed? Something like:
hg revert -r 10 myfile.pls > c:\temp\dump\myfile_revision10.pls
The cat command can be used to retrieve any revision of a file:
$ hg cat -r 10 myfile.pls
You can redirect the output to another file with
$ hg cat -r 10 myfile.pls > old.pls
or by using the --output flag. If you need to do this for several files, then take a look at the archive command, which can do this for an entire project, e.g.,
$ hg archive -r 10 ../revision-10
This creates the folder revision-10 which contains a snapshot of your repository as it looked in revision 10.
However, most of the time you should just use the update command to checkout an earlier revision. Update is the command you use to bring the working copy up to date after pulling in new changes, but the command can also be used to make your working copy outdated if needed. So
$ hg update -r 10 # go back
(look at your files, test, etc...)
$ hg update # go back to the tip
The command you use is this:
hg cat -r 10 myfile.pls > C:\temp\dump\myfile_revision10.pls
Knowing a bit of Unix helps with Mercurial commands. Perhaps cat should have a built in alias print or something similar.