Nelle Varoquaux
CBIO Mines ParisTech, U900 Institut Curie, INSERM
http://cbio.ensmp.fr/~nvaroquaux/teaching/2014-scilifelab/git.html
$ git init
Initialized empty Git repository in /home/nelle/Projets/SCBC/git-test/.git/
$ git clone http://github.com/schacon/grit.git
git config [options]
git config --global [options]
git config --system [options]
$ git config --global user.name "Your Name Comes Here"
$ git config --global user.email you@yourdomain.com
$ git config --global core.editor vim
$ git config --list
$ git add README
$ git commit -m "My commit message"
git status: show the status of the files of the repository
git log: show commit log
Pro Git Boot, by Scott Chacon: http://git-scm.com/book
git rm FILENAME
git mv FILENAME TARGET
$ git reset HEAD filename
git reset --soft HEAD^: uncommits the last commit
$ git checkout -- filename1 filename2
Initialize a git repository.
Check your configuration settings by using git config --list
Create a TODO file, and add it to the staging area.
Remove this file from the staging area.
return x ** 2
Add this to the staging area and commit it.
return np.sqrt(x)
Use git checkout to remove the changes you've made to this file. You can check what you have done using git status.
Commit everything.
git branch: manages branches
- git branch: lists the branches of the local repository
- git branch [branch_name]: creates a branch
- git branch -d [branch_name]: deletes a branch
git checkout: moves to a branch:
When a conflict emerges, you must manually edit the files:
<<<<<<< HEAD:calc.py print 'the average is', sum(x) / float(len(x)) print 'sumsqdiffs is', sum(diffs) ======= avg = sum(x) / float(len(x)) sumsqdiffs = sum(diffs) / float(len(x)) print 'average is', avg, 'and sumsqdiffs is', sumsqdiffs >>>>>>> edgier:calc.py
Remote repositories are versions of your project that are hosted on the Internet or network somewhere.
In 3 commands:
- git clone --bare --shared my_project my_project.git
- scp -r my_project.git user@git.example.com:/opt/git
- git clone user@git.example.com:/opt/git/my_project
When using grep to find files on a git repository, the resultr are going to be polluted with git's filesystem.
git grep allows to search for a pattern in the files of the index.
Allows to apply changes introduced by some commits.
Typical usecase: retrieving changes applied in a master branch into a release branch.
Lightweighted: pointer to a commit
Annotated: contains tagger name, e-mail, date, a message, can be signed and verified
- git tag -a v1.4 -m 'my version 1.4'
- git tag -s v1.4 -m 'my version 1.4'
Used to record the current state of the repository and the index, but switches back to a clean working directory:
- saves the local modifications away
- reverts back to HEAD.
When there is a conflict:
Assume you have created a branch from master, but master has moved forward. Merging will create a commit. To avoid this, you can "rebase master onto your branch"
Never rebase a branch onto master!!
git filter-branch allows you to rewrite the history of a branch.
For example, if a developper has changed email adresse, you can update it for all commits of a branch matching this developpers email.
This command is extremely dangerous. Use with care.
Fork the repository https://github.com/NelleV/SCLoft.git and clone your fork locally.
Try merging the food branch into master using the following command: git merge --ff-only food. It fails. Do you understand why ?
Allows to interactively stash files:
You can use git with an svn repository:
Submodules allow foreign repositories to be embedded within a dedicated subdirectory of the source tree, pointed to a specific commit.
the folder
Git has a lot of powerful commands. With power comes responsabilities.
The more complex the commands you use are, the higher potential very dangerous effects it can have on your repository.
If any problem occurs, you can check the connectivity and validity of the objects in your database using git fsck.
Table of Contents | t |
---|---|
Exposé | ESC |
Presenter View | p |
Source Files | s |
Slide Numbers | n |
Notes | 2 |
Help | h |