Deleting file from git cache - sublimetext2

How to auto delete file from Git cache when I deleted it by hand in sublime text 2? Is there a plugin to do so?

This is the way you can remove file/folders from git cache manually.
Remove tracking of file/folder - but keep them on disk - using
$ git rm --cached
Now they do not show up as "changed" but still show as
untracked files in
$ git status -u
Add them to .gitignore
Use
$ git config --global core.editor

Remove the definite file which you want to ignore, rather than removing all files in cache, it will reduce risk.
add to .gitignore;
delete the file/files git rm cached <file>

Related

How to remove the file from github and ignore/untrack while you add next time?

I have just come across a situation where I have added all the files to git hub with git add . command. However there are few files like I do not want to add to git hub like .gitignore which has .vscode .env and nodemodules but the issue is they do keep adding all the time when I perform the git add ..
I tried to perform certain task,
Which is to untrack the file first using
git rm --cached .gitignore
and then
git config --global core.excludesfile .gitignore
but the result is no change.
can anyone help with this, what way it should be done correctly?
Thanks
git rm -r --cached .
git add -A
git commit -am 'Removing ignored files'
The first command will un-track all files in your git repository.
The second command will then add all of the files in your git repository, except those that match rules in your .gitignore. Thus, we have un-tracked several files with just two commands.
Then the last command is to commit the changes, which will just be removed files.
when you edit anything in the .gitignore file you have to add it to the staging area and commit it first, in order to see the change commit the .gitignore first.

Cannot push to github because of large files

I am getting this error shown in the screenshot below when I try to push to Github.
I have removed any video files that were added in the previous commit using the 'git rm --cached ' command, however it is still complaining about video files begin too large, even though I have removed them from the commit... please help!
I have tried to add the mp4 files to my git attributes file so that they will be stored in Git Large File Storage, but still no joy.
I am relatively new to git and the git process but I have never had this problem when pushing files. Please help me as I cannot push anything up to github, thanks!
You can use git filter-branch command in-order to remove a big file which is wrongly committed in git
git filter-branch --tree-filter 'rm -rf path/to/your/file' HEAD
You basically need to remove the bigger files from Git history so that they are not pushed, but not from the file system.
If you mistakenly push the file in your previous commit, you can do:
git rm --cached giant_file # Stage our giant file for removal, but leave it on disk
git commit --amend -CHEAD # Amend the previous commit with your change
git push # Push our rewritten, smaller commit
If not, they recommend using BFG – repo cleaner tool for cleaning up repositories:
bfg --strip-blobs-bigger-than 1M #removes files above 1 MB

hg: replacing directory contents in one change

With hg, how can I replace the contents of a directory in one change?
More specifically, I have headers for a large C++ library checked into my repo and I'd like to update them (including adding and removing files) to the latest version of the library. And I'd like to do this in one change, rather than first a removal of the old version and then addition of the new, which would break tests and produce unhelpful diffs.
Within your mercurial repo:
# Change to parent directory of your vendor directory
cd vendor_dir/..
rm -rf vendor_dir
# unpack/copy/checkout new vendor sources into a new vendor_dir
# Tell mercurial to figure out what changed
# Feel free to play with the similarity percentage and the (-n) do nothing switch
hg addremove --similarity 70 vendor_dir
hg commit vendor_dir
Updated:
Changed to work on the parent directory since hg rm * within vendor_dir misses dot files, if any.
Change from hg rm to rm -rf because I wrongly assumed that addremove after rm would do the right thing. Hint: it doesn't.
Realized that the default similarity of 100% is not appropriate for vendor releases.
If they are all changed then, (assuming a flat directory structure:
hg remove \path\to\directory\to\replace\*.h
copy \path\to\new\files\*.* \path\to\directory\to\replace\
hg add \path\to\directory\to\replace\*.*
hg commit -m "Library SoAndSo headers replaced"
hg push
The first line says forget all the files on the next commit but then the new ones are added in the same commit - remember only the last but one line actually changes the local copy of the repository and it only becomes public on the last line.
If you do have sub-directories then you can just remove the *.h on the first line, use xcopy or explorer to copy the new directory structure into place and remove the *.* on the 3rd line.

hg remove -I PATTERN, how it works?

Ho to remove all *.bak or *.orig files in mercurial?
example:
C:\dev\web>hg stat
? Views\System\UnderConstruction.cshtml.bak
? Views\Topic\Index.cshtml.bak
? Views\Topic\MasterPage.cshtml.bak
? Web.config.bak
C:\dev\web>hg rem -I *.bak
abort: no files specified
hg remove only removes files that have already been committed. AFAIK, there is no command in mercurial to remove untracked files.
To learn how file patterns work in mercurial, run hg help patterns.
Untracked files ("?" sign) can be removed by OS, not Mercurial
You have to leave files as is, just add patterns to .hgignore and after it files, matching patterns, will not apper in hg status anymore
Correct remove command for remove tracked bak and orig files will be hg remove -I **.bak -I **.orig
You should take a look at the hg purge extension:
Delete files not known to Mercurial. This is useful to test local and
uncommitted changes in an otherwise-clean source tree.
This means that purge will delete:
Unknown files: files marked with "?" by "hg status"
Empty directories: in fact Mercurial ignores directories unless they contain files under source control management
But it will leave untouched:
Modified and unmodified tracked files
Ignored files (unless --all is specified)
New files added to the repository (with "hg add")
If directories are given on the command line, only files in these
directories are considered.
Be careful with purge, as you could irreversibly delete some files you
forgot to add to the repository. If you only want to print the list of
files that this program would delete, use the --print option.
You can do the following two commands:
D:\workspace>hg purge -I **/*.orig --all
and then:
D:\workspace>hg purge -I **/*.bak --all
Tracked files won't be deleted, but I'm guessing that's not an issue for you. Make sure that you enable the purge extension before running this, and you can do dry runs with the --print argument.

hg remove directory from repo?

I'd like to remove a directory and all the files in it from a repo.
I have removed all the files with hg remove, but how do I remove the directory itself?
Will it just automatically vanish once I commit all the removed files?
Yes. Because mercurial doesn't track directories at all, only files, it only creates directories that have files in them, and if someone hg updates to a revision any directories that become empty are automatically removed. So if you do:
hg remove directory/*
hg commit -m 'removed all files in directory'
hg update -r 0 # updates to a different revision
hg update tip # jump back to the tip
That last update would remove the directory. For everyone else it's even easier. When they hg update to your new changes their directory will just vanish (provided they have no uncommitted file in it).
hg remove dir
If you end up with empty directories and you want to get rid of them, an easy way is the purge extension. (add purge= under the [extensions] group in your .hrgc file to unlock).
You can then use
hg purge
to clean up the empty dirs... You must be careful with the purge command as it removes everything that is untracked in your repos. I strongly suggest you run a
hg purge -p
beforehand to see what the command will do ( -p will print a "test run" without doing anything.) Never forget the --help option! ;)
edit: I prefer using purge to hg update in succession as updating triggers rebuilds in my IDE if it is open (and it's a good bet it is when I do that). hg purge will probably be smoother. And you can use --all to include ignored files too (must be careful though).
To remove a directory, Just do
hg remove <dir>
hg commit -m "..."
This will remove the directory and all files under it.