This is an old revision of the document!
Table of Contents
GIT
Configuration
- ~/.gitconfig
[user] name = Name Firstname email = <firstname.name@laas.fr> [core] editor = /usr/bin/myeditor
Local repository management
- %
git init
: create a local git repository for your project in your folder - %
git add <files|dirs>
(or justgit add .
for all files) : add new or modified files to the index - %
git commit [-m <msg>]
: commit the changes of the index to the repository - %
git commit -a
: commit the changes of the working files to the repository - %
git tag -a <tag-name> [-m <msg>]
: add a tag - %
git reset –hard [<commit-hash>]
: restore the working files to the latest commit, or given commit - %
git revert <commit-hash>
: revert the given commit (<commit> can be just the beginning of its hashcode) - %
git checkout <file>
: restore a working file to the last commited version
Branches
- %
git branch <branch-name>
: create a new branch - %
git checkout <branch-name>
: switch to the given branch - %
git branch
: list available branches - %
git branch -D <branch-name>
: delete the given branch - %
git merge <branch-name>
: merge current branch with the given branch - %
git cherry-pick <commit-hash>
: apply the changes introduced by a given commit to the current branch
Collaborative repository management
- %
git clone <repo-addr>
: copy the distant repository (<repo-addr> can be “http:<repo>” or “ssh:<user>@<repo>”) - %
git pull <repo-addr>
: update from the distant repository (fetch and merge) - %
git push <repo-addr>
: send to the distant repository (merge)
Info
- %
git status
: show the status of the repository and the index - %
git log [–stat|-p]
: show the history of modifications - %
git diff
: show differences between working files and index - %
git diff –cached
: show differences between index and repository - %
git diff <commit-hash> <commit-hash>
: show differences between two arbitrary commits - %
git diff [options] > <file-name>
: save the patch to a file - %
git blame <file>
: show what revision and author last modified each line of the file