z, ? | toggle help (this) |
space, → | next slide |
shift-space, ← | previous slide |
d | toggle debug mode |
## <ret> | go to slide # |
c, t | table of contents (vi) |
f | toggle footer |
r | reload slides |
n | toggle notes |
p | run preshow |
1.7.10.4
10.7
command line
"...an Ounce of Prevention is worth a Pound of Cure...."
$ git help <command>
$ man git-<command>
$ git
usage: git [--version] [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
[-p|--paginate|--no-pager] [--no-replace-objects] [--bare]
[--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
[-c name=value] [--help]
<command> [<args>]
The most commonly used git commands are:
add Add file contents to the index
bisect Find by binary search the change that introduced a bug
branch List, create, or delete branches
checkout Checkout a branch or paths to the working tree
...
See 'git help <command>' for more information on a specific command.
$ git add --dry-run .
add '.gitignore'
add '.rvmrc'
add 'Gemfile'
...
$ git status
# On branch master
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# .gitignore
# .rvmrc
# Gemfile
...
-n
, usually short-hand for --dry-run
$ git help commit
...
-n, --no-verify
This option bypasses the pre-commit and
commit-msg hooks. See also githooks(5).
...
--dry-run
Do not create a commit, but show a list of paths
that are to be committed, paths with local
changes that will be left uncommitted and paths
that are untracked.
$ git add showoff.json
$ git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# new file: showoff.json
$ git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# new file: showoff.json
$ git reset HEAD showoff.json
$ git status
# On branch master
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# showoff.json
$ git rm references/02_slide.md
rm 'references/02_slide.md'
$ ls references/02_slide.md
ls: references/02_slide.md: No such file or directory
$ git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# deleted: references/02_slide.md
#
$ git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# deleted: references/02_slide.md
#
$ git reset HEAD references/02_slide.md
Unstaged changes after reset:
D references/02_slide.md
$ git status
# On branch master
# Changes not staged for commit:
# (use "git add/rm <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# deleted: references/02_slide.md
#
no changes added to commit (use "git add" and/or "git commit -a")
$ git checkout -- references/02_slide.md
$ git status
# On branch master
nothing to commit (working directory clean)
$ ls references/02_slide.md
references/02_slide.md
$ git status
# On branch master
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# .DS_Store
nothing added to commit but untracked files present (use "git add" to track)
$ echo .DS_Store >> .gitignore
$ cat .gitignore
.DS_Store
$ git status
# On branch master
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# .gitignore
nothing added to commit but untracked files present (use "git add" to track)
$ git status
# On branch master
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# .DS_Store
nothing added to commit but untracked files present (use "git add" to track)
$ git config --global core.excludesfile ~/.gitignore
$ cat ~/.gitconfig
...
[core]
excludesfile = ~/.gitignore
$ echo .DS_Store >> ~/.gitignore
$ cat ~/.gitignore
.DS_Store
$ cat .gitignore
$ git status
# On branch master
nothing to commit (working directory clean)
For more on ignore patterns and precendence of ignore files
$ git help gitignore
$ man gitignore
.DS_Store
is still everywhere!$ find . -type f -name ".DS_Store" -print | xargs rm -rf
$ find . -type d -name ".svn" -print | xargs rm -rf
$ git clean
$ git clean -d
$ git commit -m "Whatever"
[master 1eaaace] Whatever
1 file changed, 11 insertions(+)
$ git commit --amend
Whatever
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
# On branch master
#
# Changes to be committed:
# (use "git reset HEAD^1 <file>..." to unstage)
#
# modified: one/01_slide.md
#
Describe amending commit to fix bad message
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
# On branch master
#
# Changes to be committed:
# (use "git reset HEAD^1 <file>..." to unstage)
#
# modified: one/01_slide.md
#
$ git commit --amend
...
[master a4f0c81] Describe amending commit to fix bad message
1 file changed, 11 insertions(+)
$ git status
# On branch master
# Your branch is ahead of 'origin/master' by 4 commits.
#
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: one/01_slide.md
$ git commit --amend
Describe amending commit to fix bad message
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
# On branch master
#
# Changes to be committed:
# (use "git reset HEAD^1 <file>..." to unstage)
#
# modified: one/01_slide.md
#
$ git commit --amend
...
[master 57f0ba9] Describe amending commit to fix bad message
1 file changed, 4 insertions(+)
$ git commit -m "Whatever"
[master 1eaaace] Whatever
1 file changed, 11 insertions(+)
$ git commit --amend
[master a4f0c81] Describe amending commit to fix bad message
1 file changed, 11 insertions(+)
$ git commit --amend
[master 57f0ba9] Describe amending commit to fix bad message
1 file changed, 4 insertions(+)
--amend
, think locally$ git branch
546826_react_to_pgs_callback
faster_specs
* master
pgs
refactor_noaa_decline_reasons
$ git branch
546826_react_to_pgs_callback
faster_specs
* master
pgs
refactor_noaa_decline_reasons
$ git branch --merged
546826_react_to_pgs_callback
* master
pgs
$ git branch
546826_react_to_pgs_callback
faster_specs
* master
pgs
refactor_noaa_decline_reasons
$ git branch --no-merged
faster_specs
refactor_noaa_decline_reasons
<commit>
?$ git branch
546826_react_to_pgs_callback
faster_specs
* master
pgs
refactor_noaa_decline_reasons
$ git branch --contains
faster_specs
* master
refactor_noaa_decline_reasons
git branch
--merged
to find all branches which can be safely deleted--no-merged
to find branches which are candidates for merging into HEAD
--contains <commit>
find all branches which will need special attention if <commit>
were to be rebased or amended$ git log -p
commit 8fdd6b1a31ae4eb07ddafa7027c3e54cc4fdc9cc
Author: Craig Demyanovich <cdemyanovich@gmail.com>
Date: Thu Jun 14 21:21:57 2012 -0500
Bigger text on using an ignore file
diff --git a/one/01_slide.md b/one/01_slide.md
index a4a3fa7..b2cff87 100644
--- a/one/01_slide.md
+++ b/one/01_slide.md
@@ -235,7 +235,7 @@ command line
# .DS_Store
nothing added to commit but untracked files present (use "git add" to track)
-!SLIDE commandline incremental smaller
+!SLIDE commandline incremental small
## Use a global ignore file
$ git config --global core.excludesfile ~/.gitignore
commit 175c8c3bce2f2901f42ddc8c332b3d101ee2069a
Author: Craig Demyanovich <cdemyanovich@gmail.com>
Date: Thu Jun 14 21:18:10 2012 -0500
Better warning about changing SHAs
...
$ git show 175c8c3
commit 175c8c3bce2f2901f42ddc8c332b3d101ee2069a
Author: Craig Demyanovich <cdemyanovich@gmail.com>
Date: Thu Jun 14 21:18:10 2012 -0500
Better warning about changing SHAs
diff --git a/one/01_slide.md b/one/01_slide.md
index 3a90275..a4a3fa7 100644
--- a/one/01_slide.md
+++ b/one/01_slide.md
@@ -325,8 +325,10 @@ command line
[master a4f0c81] Describe amending commit to fix bad message
1 file changed, 11 insertions(+)
+!SLIDE center
+![Caution](../images/500px-Stop_hand_caution.svg.png)
+
!SLIDE commandline
-## WARNING: the SHA changed
$ git commit -m "Whatever"
[master 1eaaace] Whatever
$ git commit -am "Killed Mr. Clean"
[master ece75be] Killed Mr. Clean
1 file changed, 9 deletions(-)
$ git revert ece75be
Revert "Killed Mr. Clean"
This reverts commit ece75be6fa91e135cfc349341aa523d323d92e5b.
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
# On branch master
# Your branch is ahead of 'origin/master' by 2 commits.
#
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# modified: one/01_slide.md
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# images/
$ git revert ece75be
...
[master 9791a68] Revert "Killed Mr. Clean"
1 file changed, 9 insertions(+)
$ git log
commit 9791a68ebe0f454766e0d0a43c1d1e59ea943d01
Author: Craig Demyanovich <cdemyanovich@gmail.com>
Date: Thu Jun 14 23:37:19 2012 -0500
Revert "Killed Mr. Clean"
This reverts commit ece75be6fa91e135cfc349341aa523d323d92e5b.
commit ece75be6fa91e135cfc349341aa523d323d92e5b
Author: Craig Demyanovich <cdemyanovich@gmail.com>
Date: Thu Jun 14 23:36:59 2012 -0500
Killed Mr. Clean
...
$ git revert -n ece75be
$ git revert -n c9099b3
...
$ git revert -n 8fdd6b1
$ git commit -am "Reverted a few bad commits"
cheat
gem$ gem install cheat
Fetching: cheat-1.3.0.gem (100%)
Successfully installed cheat-1.3.0
1 gem installed
$ cheat git
git:
Setup
-----
git clone <repo>
clone the repository specified by <repo>; this is similar to "checkout" in
some other version control systems such as Subversion and CVS
Add colors to your ~/.gitconfig file:
[color]
ui = auto
...