I have recently switched to git.
In my previous and first commit since using git, I noticed it also listed the pyc files during the commit. I didn't think anything about it and commited and pushed them.
Now I realize they keep getting updated during the development and its very annoying seeing them in the list. It just produces too much noise.
I did some research and did echo "*.pyc" >> .gitignore in the project directory.
This didn't help though as the pyc files are still being shown. Could it be that because I have previously committed those pyc files I can no longer ignore them? (since they are tracked now and the state has changed again) If so I am damned forever or is there still hope to delete the files in the hindsight from the repository?
Thanks
Just git rm the .pyc files, and make sure your .gitignore is set to ignore them from now on. You are correct that git will not ignore the committed files because they've already been added. If you are keen about not deleting the off the disk, then use git rm --cached to delete the files. That just deletes them from the index without deleting from the disk.
Related
I reinstalled my OS (KDE neon) and I thought why not backup my project git folder, before I reinstalled I made sure I commited any code and everything in my git project folder was up-to-date.
So after reinstalling, I moved my project back onto my PC from my backup drive and ran git-status and it wants to stage nearly all of my project?
What do I do? I don't want to commit all these files again when I have not editing any of them? Its nearly 800 files it wants to stage?
You could reset your project using:
git reset --hard branch_name
This would lose any unstaged files.
Or you could stash the changes:
git stash save 'msg'
This works like the previous one, but instead it saves the unstaged files in a separate "memory" (in case you need them later on).
Now, I may assume that the reason you got that situation in the first place is maybe when you restored your data back from the drive, the OS changed some properties on those files, stuff like creation/modification dates, permissions...etc. While the content of the files has not changed but the properties are. Still, git sees them as modified files.
I have tried to search for a way to resolve this and have come up with nothing so far.
I made changes to certain files in a directory. I then performed an svn add and svn commit for those files I changed. Then (by accident) I deleted the directory in svn containing the files I just modified. (the directory names were different which is what caused the mix up).
My goal is to get back the directory I deleted with my modified files or get back just the modified files. I have tried using svn merge -c REV and recommitting. it first told me there was a tree conflict with the directory i deleted so i did an svn resolve --accept working PATH. I have also tried an svn merge -r (current):(previous) to no avail.
Please help. I am using Linux (centOS)
I just did a git commit and it deleted a few files seemingly randomly from my node_modules folder. Has anyone had this issue?
To be clear, my latest git commit deleted
delete mode 100644 node_modules/grunt-google-cdn/node_modules/google-cdn/node_modules/cdnjs-cdn-data/external/cdnjs.json
delete mode 100644 node_modules/grunt-node-inspector/node_modules/node-inspector/front-end-node/Images/src/favicon.eps
delete mode 100644 node_modules/moment/min/tests.js
delete mode 100755 node_modules/requirejs/bin/r.js
I've never seen this before and I can't begin to understand why this happened. This prevents me from building my app for deployment. Does anyone know how/why this happened and how this can be prevented in the future?
My expectation is that those files were deleted at some point (via what mechanism, I can't say).
If you're using Git 2.0 or greater, when you typed git add ., you staged the deleted files for commit. git add . basically says "I want to stage all of the changes in this repo", which in this case included deleting files.
The behavior was different in prior versions (I just validated different behavior against Git 1.9 and 2.6.3).
I only did git add . beforehand
So you asked Git to stage everything in . (the current directory). This includes deleted files:
e.g. specifying dir will record not just a file dir/file1 modified in the working tree, a file dir/file2 added to the working tree, but also a file dir/file3 removed from the working tree
If these files were deleted by some non-git process and you subsequently ran git add . and then committed, the deletes would have been committed.
Comparing the documentation for version 1.9.2 and version 2.0.0 of git-add shows that this behaviour changed in version 2.
To tell git to ignore deleted file(s) in the commit and commit all the other changes:
git add --ignore-removal .
I tried installing git-annex yesterday to backup my files. I ran git annex add . in the root of my repository tree and then a git commit. So far everything is fine.
What I didn't know git-annex was doing was turning my entire file tree into a whole bunch of symlinks. Every single file in my whole tree is now symlinked into .git/annex/objects! This is messing up my application which depends on files not being symlinks.
My question is, how do I get rid of git-annex and restore my file system to its original state? For a normal git repo I could do rm -r .git, but I'm afraid that won't do the job in git-annex. Thanks in advance.
Okay, so I stumbled upon some docs for git-annex, and they give two commands that achieve what I wanted to do:
unannex [path ...]
Use this to undo an accidental git annex add command. You can use git annex unannex to move content out of the annex at any point, even if you've already committed it.
This is not the command you should use if you intentionally annexed a file and don't want its contents any more. In that case you should use git annex drop instead, and you can also git rm the file.
uninit
Use this to stop using git annex. It will unannex every file in the repository, and remove all of git-annex's other data, leaving you with a git repository plus the previously annexed files.
I started running git annex uninit, but my god was it slow. It took about 5 minutes to "unannex" just a single file. My filesystem tree is about 200,000 files, so that was just unacceptable.
What I ended up doing was actually surprisingly simple and worked well. I used the cp -rL flags to automatically duplicate the contents of my file tree and reverse all symlinks in the duplicate copy. And it was blazing fast: around 30 seconds for my entire file tree. Only problem was that the file permissions were not retained from my original state, so I needed to run some chmod and chcon commands to fix up the permissions.
This second method worked for me because there were no other symlinks in my schema. If you do have symlinks in your schema beyond those created by git-annex, then my little shortcut probably isn't the right choice for you, and you should consider sticking with just git annex uninit.
I would like to include my own experience of using git annex uninit, in addition to OP's answer.
I didn't have full repository annexed, but only about 40 bigger files. After deciding that I have no particular benefit of using git-annex, I tried unannexing several files and it was over in several seconds per file. Then, I ran git annex uninit and it took more than a minute only for really huge files (more than few GB). Overall, it was done in about 20 minutes, which was acceptable in my case.
So, it seems that the complexity of unannexing increases with the size of annexed file tree.
If you have a v6 repository, you can do the following:
git unnannex . --fast
which replaces the symlinks w/ hardlinks instead of slowly replacing the symlinks with the original files again.
Only v6 repositories can execute the git-annex unannex command on uncommited changes, so it could be necessary to upgrade the git-annex repo to a v6 repository.
See the Official Upgrade Guide.
In my case I had to upgrade v5 -> v6 and I only had to execute
git annex upgrade
which took a few seconds and I was done.
Have you tried to use git-annex in direct mode?
Just change your repository with
git annex direct
This will not use symlinks any longer, but some git commands do not work with such annex repositories.
Check out the explanations on their website to see if this scheme fits your purposes.
Maybe the conversion process is faster then the previous mentioned tips.
I haven't tried it by myself with big repositories.
In a Mercurial repository, how to find lastly committed 10 files contained in a subdirectory? I want to do so because I'm a little worried that some files are mistakenly committed.
Using revsets is probably the best approach.
A close approximation may be hg log -r "last(file('subdirectory/*'), 10)".
This command returns the last 10 commits that touched any file in subdirectory. From there, you could review each commit for the files affected.
If --template "{files}\n" is added to the command, it will list the files touched in each of the commits. However, the list would include files outside subdirectory as well. See hg help templates for details.