Trying to add .rvmrc to ignore, its not working - ruby-on-rails

So I modified my .rvmrc to what I need on my server, commit to git and pushed to origin.
Then I added .rvmrc to my .gitignore, but when I do a git status it shows the file has been modified.
I'm trying to fix it so it has my local settings now since the master has the server's version, and I don't want it to pickup the change I made to my local rvm settings since I added it to my .gitignore.

From the Git Documentation at Kernel.org:
A gitignore file specifies intentionally untracked files that git should ignore. Files already tracked by git are not affected.
The solution follows:
To stop tracking a file that is currently tracked, use git rm --cached.
I would do this:
$ git rm --cached .rmvrc
and try again.

Try:
git update-index --assume-unchanged .rvmrc

Related

Git commit without files or folder

Git is telling me to commit some 10000 changes but here's the catch, I deleted the folder in which the files to commit are located. Any thoughts on how I can stop git from telling me this.
Run git reset --hard origin/<branch_name> and the branch will realign with your origin counterpart.
If you want your directory or files to do not track by git
Run this command
git update-index --assume-unchanged <directory> or <file>
If those files in the folder are don't need in repo, you may add the folder path into .gitignore file. then git won't ask again to commit changes.

Git merge conflict with workspace.xml

I'm trying to push my Rails project to Heroku, but Git isn't allowing me to do anything at the moment. Here's what I've done so far:
git push heroku failed because the heroku branch was "ahead" of my local branch, which should not have been possible.
I pulled and there was a conflict with .idea/workspace.xml. I wasn't able to find out what that file is, but it's huge and Git wrote all kinds of garble to it. Too much to manually "resolve" conflicts.
I saw some stackoverflow posts talking about git-ignoring that file (maybe it's some IDE file for RubyMine or something?), so I tried to move the file away to avoid the conflict
I ran git add -A (also tried git add . and git add)
git commit --amend fails because "You are in the middle of a merge"
git merge --abort fails because "Untracked working tree file '.idea/workspace.xml' would be overwritten by merge (despite the fact that the file has been moved)
git reset --merge fails for the same reason.
How can I make Git work again?
.idea/workspace.xml
This file is your idea workspace files. They are generated by IntelliJ tools.
I saw some stackoverflow posts talking about git-ignoring that file (maybe it's some IDE file for RubyMine or something?), so I tried to move the file away to avoid the conflict
Simply add the folder to your .gitignore but since its already committed you will have to remove it from the repository:
# Quit the merge
git merge --abort
# remove the whole folder from the repo
git rm -rf --cached .idea/
# add it to the .gitignore: idea/
# add and commit your changes
git add .- A
git commit -m " Removed idea folder"
git push origin <branch>
If you still unable to do it?
First reset the code to the previous state and then do the above code again.
The reset will take you to your last commit before the pull
git commit -am "message" worked (as opposed to amending a commit)
I have resolved a similar problem by simply deleting the workspace.xml file. By building and running the program again idea will autogenerate a compatible file.

Unstage a file in previous commits in git

We use git together with our iOS app, and we're now planning to make the app's code open source. The problem is we don't want people to have access to our API keys because the API itself shouldn't be accessible by the public.
The API keys are all in APIConstants.h and .m. I'm thinking of unstaging them in future commits, but I understand that people can still check out older commits. Is there any way I can disable the checking out of those two files even from older commits?
The other solution I can think of is deleting the .git folder altogether, add APIConstants to the .gitignore, and doing git init again at the expense of deleting all of our commit history.
Do it like this:
$ git rm --cached APIConstants.h
$ echo APIConstants.h >> .gitignore
$ git add .gitignore
$ git commit -m "Remove and ignore APIConstants.h"
I think you can accomplish this by running the following command:
git rm --cached file
and then adding the file to your .gitignore file so it's not added again later.
adding the file to .gitignore will guarantee that the file won't be included in the future commits.
However, as you said, it is already available and users can still download the old file. You could remove them from the repository altogether..
git rm --cached <file>
Or, if you want to tell the repository to stop tracking a file, you could use..
git update-index --assume-unchanged <file>
and this can be reverted by using,
git update-index --no-assume-unchanged <file>

Accidentally created a git submodule

So I was developing a API Client gem, which was working great, had it's own github repository and my team lead decided that he wanted me to move this client api into the api repository itself. So I copied the files over into it's own directory, removed the .git directory from the client's directory, and merged it into master. Worked great.
However, now when I try to create a branch off of master, the directory shows up a submodule on github, and isn't tracked in my local git. There is no .gitmodules folder, and no mention of submodules whatsoever. I can't create a new branch because it says that there are untracked files that will get overwritten (all the files in my client gem directory) but as far as I can tell there's no way for me to start tracking these files. I can access the directory just fine, but as soon as I modify a file, the change doesn't show up in the api projects git.
What do I do?
If there is no .git folder or file in that subfolder, all you need to do is git rm --cached [folder] followed by git add [folder]/*
Running git rm --cached --ignore-unmatch client then allowed me to git add client/

Starting over with Git

I decided to learn how to use Version Control over Christmas break, so I downloaded Git, opened a GitHub account and started reading the online tutorial linked to from the GitHub website. When I got to this part http://progit.org/book/ch2-2.html I got stuck because I wasn't sure how to add files. For instance, I tried
git add C:/Finish.txt
And it said
Fatal: 'C:/Finish.txt' is outside repository
I was confused until I remember that a long time ago I had tried teaching myself Ruby on Rails and played around with Git back then. It never really went anywhere, but there's all this residual stuff floating around my system and I don't know how to change it. For instance, my Untracked files (which should be empty) are rails_projects/ and sample/.
How can I just erase all the old stuff and start over?
You should make a folder for your repository, move Finish.txt to that repository, then do git add.
For example:
# here you create C:\myrepo
cd C:\myrepo
git init .
# here you edit C:\myrepo\Finish.txt
git add Finish.txt
git commit -m "Added Finish.txt"
Start a new repository, e.g.
c:
md c:\newrepo
cd c:\newrepo
git init .
copy \Finish.txt .
git add Finish.txt
git commit -m "started over"
I strongly recommend against adding anything to C:\, let alone putting a git repo there. Unless of course you want to accidentally add all of your system disk to git :)
I can also heartily recommend using TortoiseGit which has some excellent explorer integration.
Delete any .git folder that you find in your drive.
To create a repo go to a folder that you want the repo in ( and not just randomly), do:
git init
Then proceed... Add only files that you put within this repo and not randomly from some location.
It would be very unusual to have the root directory of your hard drive be a git repository. That's probably why it's giving you the error.
git repositories are typically in a subdirectory and that subdirectory is typically a project.
To initialize a subdirectory as a git repository, you'd do:
git init (directory)
Then you'd add your files and commit.

Resources