Git

This page is comprehensive. It may has everything I need to know about Git.

Basic topics

# Initiate a repository.
git init
 
# Show status including unstaged changes.
git status

# Add files.
git add

# Commit a change.
git commit

# Show commits log
git log
 
# A much good-looking log
git reflog

# Show list of files in committed changes
git whatchanged

# Show file differences between commits
# Show uncommitted file changes if without commits specified.
git diff
 
# Show various committed changes
git show

# Show change history of a file
git log -p filename

# Show the file's entire history, including history beyond renames.
git log --follow -p bar 
 
# Show change history of a file line by line
git blame filename

# Show branches
git branch
git br

# Checkout a branch
git checkout [branch]
git co [branch]

* Download a branch from remote 
git checkout -b newlocalbranchname origin/branch-name

* Show information about files in the index and the working tree
git ls-files
git ls

* Recursively add *.wiki files in the current directory and its sub-directories. --all add all files, -u only stage the files previously tracked.
find . -name "*.wiki" -print0 | xargs -0 git add --all
find . -name "*.wiki" -print0 | xargs -0 git add -u

* Remove files from git index but keep them in the file system
git rm --cached filename

* Remove files from index but keep them in working tree.
find . -name "*.html" -print0 | xargs -0 git rm --cached

* Retrieve a single file from secific revision
git show master:test/test.png > ~/tmp/test.png

* Undo changes in a file; Revert one file to a specific commit
git checkout -- filename # revert one file to last commit
git checkout origin/master -- filename
git checkout HEAD -- filename # the version from the most recent commit
git checkout HEAD^ -- filename # the version before the most recent commit

Examples

mkdir newproject
cd newproject
git init

echo "Hello world" > hello
echo "Silly example" > example
git add hello example

git status
git commit -m "Initial commit of git repository"

git branch robin
git checkout robin

echo "It's a new day for git" >> hello
git show
git diff

git commit -am "new day for git"

git diff master robin

git tag mytag f0af6283824688f9d23426031734657661b54388

git checkout -f foo.c # i don't understand this

Extended topics

The 2nd commit overwrite the 1st.

Customize

$ git config color.ui true
$ git config format.pretty oneline

.gitconfig

[color]
  ui = true

[alias]
  st = status
  ci = commit
  br = branch
  co = checkout
  df = diff
  dc = diff --cached
  lg = log -p
  lol = log --graph --decorate --pretty=oneline --abbrev-commit
  lola = log --graph --decorate --pretty=oneline --abbrev-commit --all
  ls = ls-files

  # Show files ignored by git:
  ign = ls-files -o -i --exclude-standard

.gitignore

indicating which files should be ignored by git indexing. .git/info/exclude has the save function as the .gitignore

Branch specific configuration

[http://stackoverflow.com/questions/1836742/using-git-how-do-i-ignore-a-file-in-one-branch-but-have-it-committed-in-another how do I ignore a file in one branch but have it committed in another branch?]

Git on Mac OS X

Git on Linux

github web hosting

http://pages.github.com/

https://github.com/blog/272-github-pages

git over ssh

The following 2 methods are the same. Method 1

git push ssh://user@server:file.git master

Method 2

git remote add origin ssh://user@server:file.git
git push origin master

References

Homepage
Comments

Hide Comments