scratch/content/html/en/blog/2009-11-12-Git-for-n00b/commandes-avancees.md

143 lines
2.3 KiB
Markdown
Raw Normal View History

2010-02-17 12:27:01 +00:00
-----
isHidden: false
menupriority: 30
kind: article
created_at: 2009-11-12T11:39:54+02:00
2010-04-30 07:36:43 +00:00
title: Git for n00b
2010-05-09 12:53:46 +00:00
author_name: Yann Esposito
author_uri: yannesposito.com
2010-04-30 07:36:43 +00:00
subtitle: Command List
2010-02-17 12:27:01 +00:00
tags:
- git
-----
# Command List
## Command for each functionality
In the first part, we saw the list of resolved problem by [Git][git]. To resume [Git][git] should do:
- get others modifications,
- send modifications to others,
- get back in time,
- list differences between each version,
- name some versions in order to refer easily to them,
- write an historic of modifications,
- know who did what and when,
- manage conflicts,
- easily manage branches.
2010-04-15 09:45:50 +00:00
2010-02-17 12:27:01 +00:00
### get others modifications
2010-04-15 09:45:50 +00:00
<div><code class="zsh">
2010-02-17 12:27:01 +00:00
$ git pull
2010-04-15 09:45:50 +00:00
</code></div>
2010-02-17 12:27:01 +00:00
### send modifications to others
2010-04-15 09:45:50 +00:00
<div><code class="zsh">
2010-02-17 12:27:01 +00:00
$ git push
2010-04-15 09:45:50 +00:00
</code></div>
2010-02-17 12:27:01 +00:00
or more generally
2010-04-15 09:45:50 +00:00
<div><code class="zsh">
2010-02-17 12:27:01 +00:00
$ git pull
$ git push
2010-04-15 09:45:50 +00:00
</code></div>
2010-02-17 12:27:01 +00:00
### get back in time
#### For all tree
2010-04-15 09:45:50 +00:00
<div><code class="zsh">
2010-02-17 12:27:01 +00:00
$ git checkout
2010-04-15 09:45:50 +00:00
</code></div>
2010-02-17 12:27:01 +00:00
2010-04-15 09:45:50 +00:00
<div><code class="zsh">
2010-02-17 12:27:01 +00:00
$ git revert
2010-04-15 09:45:50 +00:00
</code></div>
2010-02-17 12:27:01 +00:00
revert three version before (see my `.gitconfig` file).
2010-04-15 09:45:50 +00:00
<div><code class="zsh">
2010-02-17 12:27:01 +00:00
$ git uncommit 3
2010-04-15 09:45:50 +00:00
</code></div>
2010-02-17 12:27:01 +00:00
Undo the las merge (if something goes wrong)
2010-04-15 09:45:50 +00:00
<div><code class="zsh">
2010-02-17 12:27:01 +00:00
$ git revertbeforemerge
2010-04-15 09:45:50 +00:00
</code></div>
2010-02-17 12:27:01 +00:00
#### For one file
2010-04-15 09:45:50 +00:00
<div><code class="zsh">
2010-02-17 12:27:01 +00:00
$ git checkout file
$ git checkout VersionHash file
$ git checkout HEAD~3 file
2010-04-15 09:45:50 +00:00
</code></div>
2010-02-17 12:27:01 +00:00
### list differences between each version
list files being modified
2010-04-15 09:45:50 +00:00
<div><code class="zsh">
2010-02-17 12:27:01 +00:00
$ git status
2010-04-15 09:45:50 +00:00
</code></div>
2010-02-17 12:27:01 +00:00
differences between last version files and local files
2010-02-17 12:27:01 +00:00
2010-04-15 09:45:50 +00:00
<div><code class="zsh">
2010-02-17 12:27:01 +00:00
$ git diff
2010-04-15 09:45:50 +00:00
</code></div>
2010-02-17 12:27:01 +00:00
differences between some version and local files
2010-02-17 12:27:01 +00:00
2010-04-15 09:45:50 +00:00
<div><code class="zsh">
2010-02-17 12:27:01 +00:00
$ git diff VersionHash fichier
2010-04-15 09:45:50 +00:00
</code></div>
2010-02-17 12:27:01 +00:00
### name some version to refer to them in the future
2010-04-15 09:45:50 +00:00
<div><code class="zsh">
2010-02-17 12:27:01 +00:00
$ git tag 'toto'
2010-04-15 09:45:50 +00:00
</code></div>
2010-02-17 12:27:01 +00:00
### show historic of modifications
2010-04-15 09:45:50 +00:00
<div><code class="zsh">
2010-02-17 12:27:01 +00:00
$ git log
$ git lg
$ git logfull
2010-04-15 09:45:50 +00:00
</code></div>
2010-02-17 12:27:01 +00:00
### know who did what and when
2010-02-17 12:27:01 +00:00
2010-04-15 09:45:50 +00:00
<div><code class="zsh">
2010-02-17 12:27:01 +00:00
$ git blame fichier
2010-04-15 09:45:50 +00:00
</code></div>
2010-02-17 12:27:01 +00:00
### handle conflicts
2010-04-15 09:45:50 +00:00
<div><code class="zsh">
2010-02-17 12:27:01 +00:00
$ git conflict
2010-04-15 09:45:50 +00:00
</code></div>
2010-02-17 12:27:01 +00:00
### manage branches
To create a branch:
2010-04-15 09:45:50 +00:00
<div><code class="zsh">
2010-02-17 12:27:01 +00:00
$ git branch branch_name
2010-04-15 09:45:50 +00:00
</code></div>
2010-02-17 12:27:01 +00:00
To change the current branch:
2010-04-15 09:45:50 +00:00
<div><code class="zsh">
2010-02-17 12:27:01 +00:00
$ git checkout branch_name
2010-04-15 09:45:50 +00:00
</code></div>
2010-02-17 12:27:01 +00:00
[git]: http://git-scm.org "Git"