reset How to move in a git tree git checkout, HEAD References git branch, tag, merge History manipulation git cherry-pick, git rebase (—interactive) Working with a remote server git clone, remote, push, pull, fetch, merge, rebase
user: git config --global user.name "Matthieu Moquet" git config --global user.email [email protected] write in your global ~/.gitconfig Your real name
a commit: • is a snapshot of the sources • is identified by its hash (sha1) • has one (or many) parents • is immutable git commit once a commit is done, you can NOT modify it!
git add README.md ➜ git commit ➜ git status Initialized empty Git repository in /path/to/myproject/.git/ Untracked files: (use "git add <file>..." to include in what will be committed) ! README.md Changes to be committed: (use "git reset HEAD <file>..." to unstage) ! new file: README.md [master (root-commit) 4b60dee] My commit ➜ git status On branch master nothing to commit, working directory clean
index 540550a..2f10d41 100644 --- a/README.md +++ b/README.md @@ -1 +1 @@ -This is an old line +This is the new line Stage this hunk [y,n,q,a,d,/,e,?]? y diff --git a/src/Foobar.php b/src/Foobar.php index 540550a..2f10d41 100644 --- a/src/Foobar.php +++ b/src/Foobar.php @@ -1 +1 @@ -class Foobar -{ - const BAZ = 'world'; -} Stage this hunk [y,n,q,a,d,/,e,?]? git add patch
! More detailed explanatory text, if necessary. Wrap it to about 72 characters or so. In some contexts, the first line is treated as the subject of an email and the rest of the text as the body. The blank line separating the summary from the body is critical (unless you omit the body entirely); tools like rebase can get confused if you run the two together. ! Write your commit message in the imperative: "Fix bug" and not "Fixed bug" or "Fixes bug." ! - Bullet points are okay, too - Use a hanging indent Best practice Open in your editor http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html
Sep 18 13:37:00 2014 +0200 ! Allow scope to be defined in the request entity body ! As defined in the RFC 6749: http://tools.ietf.org/html/rfc6749#section-4.4.2 ! Note that this change is backward compatible as it will first look up the request query.
Jul 29 17:00:33 2014 +0200 ! Use UserChecker in OAuth2 listener ! In order to deny block users on every API call ! Fix https://jira.example.net/browse/FOO-123
the staging area git commit Oops, I made a mistake (typo, forget file, wrong commit msg) git add the_file.txt Add the concerned file into the staging area
13:37:00 2014 +0200 ! Allow scope to be defined in the request entity body ! As defined in the RFC 6749: http://tools.ietf.org/html/rfc6749#section-4.4.2 ! Note that this change is backward compatible as it will first look up the request query. ! commit c851bca7bf85504fe82639342acb237e9fc87420 Author: Matthieu Moquet <[email protected]> Date: Tue Jul 30 12:34:56 2014 +0200 ! Update README.md ! commit c1230da7409d22fe78263da777da237e9fc702d4 Author: Matthieu Moquet <[email protected]> Date: Tue Jul 29 17:00:33 2014 +0200 ! Use UserChecker in OAuth2 listener ! In order to deny block users on every API call ! Fix https://jira.example.net/browse/FOO-123 git log
# r, reword = use commit, but edit the commit message # e, edit = use commit, but stop for amending # s, squash = use commit, but meld into previous commit # f, fixup = like "squash", but discard this commit's log message # x, exec = run command (the rest of the line) using shell
to date Updating 7afe47a..fb562e8 Fast-forward ➜ git:(master) git checkout -b feat-something-1234 # start new branch ➜ git:(feat-something-1234) vim files ; git add -p ; git commit # commit code Switched to a new branch 'feat-something-1234' ➜ git:(feat-something-1234) git push -u origin feat-something-1234 To ssh://git@server/path/to/project.git + fb562e8...4b60dee feat-something-1234 -> feat-something-1234 [feat-something-1234 4b60dee] Some commit message ➜ git:(feat-something-1234) git rebase origin/master # update your branch First, rewinding head to replay your work on top of it... Applying: Some commit message ➜ git:(feat-something-1234) git fetch -p # later, before merging ➜ git:(feat-something-1234) git push -f # push force To ssh://git@server/path/to/project.git + fb562e8...4b60dee feat-something-1234 -> feat-something-1234 (force update) ➜ git:(feat-something-1234) stash pull-request master # open a PR ➜ git:(feat-something-1234) meps deploy # deploy on maquette
first time you push it) git push Use the shortcut the next time [push] # git < v2.0 # 'nothing' : Do not push anything # 'matching' : Push all matching branches (default) # 'upstream' : Push the current branch to whatever it is tracking # 'current' : Push the current branch default = upstream
your change, but don’t want to commit? git stash pop git stash list Try not to have too many thing in your stash, otherwise you will forgot it git stash show -p stash@{0}