How to unstage files?
git rm --cached filename
You can also unstage files recursively by:
git rm -r --cached gen
(2010-05-18)
integration to IDEs
EGit - Eclipse plugin for Git.
branch
You are always in a branch in git. The branch created with git init command is called 'master'.
You can have multiple branches. To show all the branches, use
git branch. You can switch to a different branch by
git checkout command.
To create a new branch, use
git branch branchname.
git checkout -b branchname is a shortcut to create a new branch and switch to it.
git branch -d branchname will delete a specified branch.
What is HEAD?
HEAD is the special symbol to refer the current branch. A Branch is referred by a head, which is the tip of a branch.
% git branch
experimental
* master <--- There are two branches and currently master branch is selected.
% cat .git/HEAD
ref: refs/heads/master <--- HEAD is referring the head of master branch.
% git checkout experimental
Switched to branch "experimental"
% cat .git/HEAD
ref: refs/heads/experimental <--- HEAD is now referring the head of experimental branch.
To see which branch you're using, use
git branch.
branch and file modification
When you modify a file in a branch and haven't commited, you cannot switch to a different branch.
Also, file you created will be carried to a branch you switched.
Revert
git revert is used for a different meaning than other version control systems such as svn.
Revert to the last committed state
git reset --hard HEAD
--hard changes the working tree and index.
Revert a single file to the repository version
git checkout -- lib/casserver/localization.rb
git checkout HEAD -- db/development.sqlite3
git setup for Rails project
Create .gitignore file with following content:
log/*.log
tmp/**/*
doc/api
doc/app
If you already committed some of these files, remove them using git rm.
git rm -f log/development.log
Initialize a repository
% cd target
% git init
This commands create a git repository at target/.git.
.git/config - configuration file for the repository.
.git/description - a file used by gitweb utility.
The git index is used as a staging area between a working directory and a git repository.
Files in "Changed but not updated" is not in the index.
Show the list of remote git repositories
% git remote show
origin
upstream
It shows the list of the remote repository names.
To see more details, use -v
% git remote -v show
origin git@github.com:gaku/rubycas-server.git
upstream git://github.com/gunark/rubycas-server.git
Pull a specific version of a file with git
git checkout
commit path
git checkout ceb17f9984bd59d2fe30aa9f8834d700b1f59de2 db/development.sqlite3
I got the commit name with git log command.
Is .gitignore not working?
Even though I have the following line in .gitignore file, changes are showing up in git status.
.gitignore doesn't have effect to already tracked files. Remove it from repository (git rm --cached ...) or use git update-index --assume-unchanged.
(2009-06-25)