Write some code
$ mkdir sayings $ cd sayings $ vim northern.txt
Ay up Were tha born in a barn?
Create an empty project
$ git initInitialized empty Git repository in /home/andy/sayings/.git/
Ask git what's happening
$ git status# On branch master # # Initial commit # # Untracked files: # (use "git add <file>..." to include in what will be committed) # # northern.txt nothing added to commit but untracked files present (use "git add" to track)
Add the file to source control
$ git add northern.txt
The file is "staged"
$ git status# On branch master # # Initial commit # # Changes to be committed: # (use "git rm --cached <file>..." to unstage) # # new file: northern.txt #
Finish the change
$ git commit
First commit: started with some northern.|
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
# On branch master
#
# Initial commit
#
# Changes to be committed:
# (use "git rm --cached <file>..." to unstage)
#
# new file: northern.txt
#
The commit worked
$ git commit# On branch master [master (root-commit) 813932a] First commit: started with some northern. 1 file changed, 3 insertions(+) create mode 100644 northern.txt$ git status# On branch master nothing to commit (working directory clean)
Add a file, modify one
$ vim southern.txt
Cor blimey Oi oi
Add a file, modify one
$ vim northern.txt
Ay up
Ee by gum
Were tha born in a barn?
Ask git what's going on
$ git status# On branch master # 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: northern.txt # # Untracked files: # (use "git add <file>..." to include in what will be committed) # # southern.txt no changes added to commit (use "git add" and/or "git commit -a")
Check what you changed
$ git diff northern.txtdiff --git a/northern.txt b/northern.txt index bbb4a54..993a13e 100644 --- a/northern.txt +++ b/northern.txt @@ -1,3 +1,4 @@ Ay up +Eey by gum Were tha born in a barn?
Tell git about your new file
$ git add southern.txt
Ask git what's going on
$ git status# On branch master # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # new file: southern.txt # # 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: northern.txt #
Tell git you changed a file
$ git add northern.txt
Ask git what's going on
$ git status# On branch master # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # modified: northern.txt # new file: southern.txt #
Finish the change
$ git commit
Added some southern, and a new northern.|
# 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 <file>..." to unstage)
#
# modified: northern.txt
# new file: southern.txt
#
The commit worked
$ git commit[master 9af3c75] Added some southern, and a new northern. 2 files changed, 4 insertions(+) create mode 100644 southern.txt$ git status# On branch master nothing to commit (working directory clean)
What happened before?
$ git logcommit c5ec6fd107c540d4e21c0f8ef09678cf3922edbf Author: Andy Balaam <andybalaam at artificialworlds.net> Date: Fri Mar 15 10:36:43 2013 +0000 Added some southern, and a new northern. commit de27edc0c3667569ce7736de376e1787b1284208 Author: Andy Balaam <andybalaam at artificialworlds.net> Date: Fri Mar 15 10:33:45 2013 +0000 First commit: started with some northern.
Details
$ git show de27commit de27edc0c3667569ce7736de376e1787b1284208 Author: Andy Balaam <andybalaam at artificialworlds.net> Date: Fri Mar 15 10:33:45 2013 +0000 First commit: started with some northern. diff --git a/northern.txt b/northern.txt new file mode 100644 index 0000000..bbb4a54 --- /dev/null +++ b/northern.txt @@ -0,0 +1,3 @@ +Ay up +Were tha born in a barn?
Get stuck into some work
$ vim southern.txt
Cor blimey
Oi oi
Awight lads
Ow's it goin?
Where to guvnor?
Me old China
Urgent customer issue!
$ git status# On branch master # 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: southern.txt # no changes added to commit (use "git add" and/or "git commit -a")
Just stash it
$ git stashSaved working directory and index state WIP on master: 9af3c75 Added some southern, and a new northern. HEAD is now at 9af3c75 Added some southern, and a new northern.$ git status# On branch master nothing to commit (working directory clean)
Make the fix
$ vim southern.txt
Gor blimey
Oi oi
Check in the fix
$ git add . $ git commit -m "Fixed urgent C/G issue"[master 12c3148] Fixed urgent C/G issue 1 file changed, 1 insertion(+), 1 deletion(-)
Go back to what you were doing
$ git stash liststash@{0}: WIP on master: 9af3c75 Added some southern, and a new northern.
Go back to what you were doing
$ git stash popAuto-merging southern.txt # On branch master # 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: southern.txt # no changes added to commit (use "git add" and/or "git commit -a") Dropped refs/stash@{0} (b6ac27b97b3db493370545b7b5042c56fb9acb2f)
Go back to what you were doing
$ git diff southern.txtdiff --git a/southern.txt b/southern.txt index 624bd2a..1d34fc0 100644 --- a/southern.txt +++ b/southern.txt @@ -1,3 +1,7 @@ Gor blimey Oi oi +Awight lads +Ow's it goin? +Where to guvnor? +Me old China
Videos | youtube.com/user/ajbalaam |
---|---|
@andybalaam | |
Blog | artificialworlds.net/blog |
Projects | artificialworlds.net |