Exprimiendo Git
Sobre mi

@ialcazar
http://israelalcazar.com
Cuña publicitaria

Curso de Git
16 – 17 Diciembre en Madrid

http://bit.ly/curso-git
Movember
Iniciativa de lucha contra e...
First of all…

Clear your mind
GIT BASIS
History
1972: Source Code Control System (SCCS): Closed source,
free with Unix
1982: Revision Control System (RCS) : Cross...
History
2000: Apache Subversion. Snapshot of the directory not
just the file. Transactional commits.
2000: BitKeeper SCM. ...
Git origin

It was born in 2005, developed by the kernel linux
team, leaded by Linus Torvalds.
Tries to improve BitKeeper.
What is a DVCS

They can share code
A programmer,
a repository

A programmer,
a repository

A programmer,
a repository

Ev...
GIT INTERNALS (I)
Internal Areas

Git has the following areas:
Staging Area / Index

Intermediate zone where next commit is prepared.
File Status Lifecycle

Each file in your working directory can be in one of
two states: tracked or untracked.
Tracked file...
File Status Lifecycle

Tracked	
  
stashing

A great way to pause what you are currently
working on and come back to it later.
$ git stash: Stash your change...
stashing

$ git stash pop: apply the top stash
$ git stash drop <id>: Manually delete stashes
$ git stash clear: Delete al...
Commands

- 
- 
- 
- 
- 
- 

git
git
git
git
git
git

stash list
stash save "mensaje”
stash pop
stash show stash@{0}
stash...
Example of use: stash

¡Stop	
  working	
  and	
  
fix	
  this	
  bug!	
  
Example of use: stash

¡Fu&%&/&/&	
  
mother!	
  
GIT INTERNALS (II)
HEAD

HEAD is a pointer that points to the current
branch.
When you change to a different branch, HEAD
changes to point to...
HEAD

Hands-on
$ cd .git
$ cat HEAD
ref: refs/heads/master
$ git checkout –b newFeature
$ cat HEAD
ref: refs/heads/newFeat...
Double Dash --

You can use -- to:
§  Separate options from a list of arguments:
$ git diff –w master origin -- tools/Mak...
Basic Flow: First Commit
Working	
  Area	
  

Index	
  

Local	
  Repository	
  

git	
  add	
  <files>	
  
git	
  commit	
...
REFS AND SYMREFS
Ref

§  A symbolic reference , or symref , is a name that
indirectly points to a Git object. It is still just a
ref.
§  ...
Symrefs

HEAD
ORIG_HEAD
Symrefs

HEAD
Always refers to the most recent commit on the
current branch.
When you change branches, HEAD is updated to
...
Symrefs

ORIG_HEAD
Certain operations, such as merge and reset,
record the previous version of HEAD in ORIG_HEAD
just prio...
Relative Commit Names

Git provides mechanism for identifying a commit
relative to another reference:
^: One commit before...
Relative Commit Names

C	
  is	
  a	
  commit	
  
C^^	
  	
  
C~3	
  

C~1	
  	
  

C~2	
  

C^	
  	
  
	
  	
  	
  	
  	
...
COMMITS
What is a commit

A commit is used to record changes to a
repository.
When a commit occurs, Git records a “snapshot” of
th...
Format

$ git commit -m “Message”
$ git commit -am “Message”
$ git commit -m “Message” <file>
$ git commit --amend
Example of use: --amend

Fixing a typo
Commit history

You can see the history of commits:
$ git log (same as git log HEAD)
$ git log <commit-name>: The log star...
Commit history

Specify a commit range (since..until)
$ git log master~12..master~10
Show only commits for a path
$ git lo...
Commit history

Show commits with a regular expression
$ git log --grep=‘reg-exp’
--no-merges: Removes merge commits
Show ...
FIXING COMMITS
Fixing commits Flow

1. Discard changes in a file in the index to the
copy in working directory
$ git checkout -- <files>
...
Basic Flow: Reset

You can reset some status of your repository:
$ git reset
$ git reset HEAD <file>
$ git reset --soft <c...
Basic Flow: Reset
Working	
  Area	
  

Index	
  

Local	
  Repository	
  

git	
  add	
  <files>	
  
git	
  commit	
  

git...
Revert
Undoes a committed snapshot but instead of removing the
commit appends a new commit undoing changes introduced by
t...
Revert vs Reset

Revert undoes a single commit, it does not “revert”
back to the previous state of a project.

1	
  

2	
 ...
Example of use: reset

Premature commits in a branch
Rebasing interactive

git rebase –i <commit-base>
Alter individual commits removing, splitting and
altering an existing se...
Example of use

Squashing

Split

Change commits in your
past history
Preguntas

Israel	
  Alcázar	
  
	
  
	
  
@ialcazar	
  
Exprimiendo GIT
Upcoming SlideShare
Loading in …5
×

Exprimiendo GIT

1,091 views

Published on

Charla impartida en BetaBeers Madrid el 23/10/2013

Published in: Technology
1 Comment
2 Likes
Statistics
Notes
No Downloads
Views
Total views
1,091
On SlideShare
0
From Embeds
0
Number of Embeds
108
Actions
Shares
0
Downloads
0
Comments
1
Likes
2
Embeds 0
No embeds

No notes for slide

Exprimiendo GIT

  1. 1. Exprimiendo Git
  2. 2. Sobre mi @ialcazar http://israelalcazar.com
  3. 3. Cuña publicitaria Curso de Git 16 – 17 Diciembre en Madrid http://bit.ly/curso-git Movember Iniciativa de lucha contra el cáncer de próstata http://es.movember.com
  4. 4. First of all… Clear your mind
  5. 5. GIT BASIS
  6. 6. History 1972: Source Code Control System (SCCS): Closed source, free with Unix 1982: Revision Control System (RCS) : Cross platform. Open Source. More features and faster. They only could work with one file at the same time 1986-1990: Concurrent Versions System (CVS): Concurrent users working on the same file. Open Source.
  7. 7. History 2000: Apache Subversion. Snapshot of the directory not just the file. Transactional commits. 2000: BitKeeper SCM. Closed source, proprietary. Distributed version control. The community version was free. Used for source code of the Linux kernel from 2002-2005 April 2005: The community version not free anymore
  8. 8. Git origin It was born in 2005, developed by the kernel linux team, leaded by Linus Torvalds. Tries to improve BitKeeper.
  9. 9. What is a DVCS They can share code A programmer, a repository A programmer, a repository A programmer, a repository Everyone has a local repository
  10. 10. GIT INTERNALS (I)
  11. 11. Internal Areas Git has the following areas:
  12. 12. Staging Area / Index Intermediate zone where next commit is prepared.
  13. 13. File Status Lifecycle Each file in your working directory can be in one of two states: tracked or untracked. Tracked files are files that were in the last snapshot; they can be unmodified, modified, or staged. Untracked files are everything else.
  14. 14. File Status Lifecycle Tracked  
  15. 15. stashing A great way to pause what you are currently working on and come back to it later. $ git stash: Stash your changes away $ git stash apply: Bring work back E.g: git stash apply stash@{1} $ git stash list: List of stashes
  16. 16. stashing $ git stash pop: apply the top stash $ git stash drop <id>: Manually delete stashes $ git stash clear: Delete al of the stored stashes.
  17. 17. Commands -  -  -  -  -  -  git git git git git git stash list stash save "mensaje” stash pop stash show stash@{0} stash apply stash@{0} diff stash@{0}
  18. 18. Example of use: stash ¡Stop  working  and   fix  this  bug!  
  19. 19. Example of use: stash ¡Fu&%&/&/&   mother!  
  20. 20. GIT INTERNALS (II)
  21. 21. HEAD HEAD is a pointer that points to the current branch. When you change to a different branch, HEAD changes to point to the new one. The current HEAD is local to each repository, and is therefore individual for each developer.
  22. 22. HEAD Hands-on $ cd .git $ cat HEAD ref: refs/heads/master $ git checkout –b newFeature $ cat HEAD ref: refs/heads/newFeature
  23. 23. Double Dash -- You can use -- to: §  Separate options from a list of arguments: $ git diff –w master origin -- tools/Makefile §  Separate an explicitly identify filenames # Checkout the tag named “main.c” $ git checkout main.c #Checkout the file named “main.c” $ git checkout -- main.c
  24. 24. Basic Flow: First Commit Working  Area   Index   Local  Repository   git  add  <files>   git  commit   git  rm  -­‐-­‐cached  <file>   git  reset  HEAD  <file>  
  25. 25. REFS AND SYMREFS
  26. 26. Ref §  A symbolic reference , or symref , is a name that indirectly points to a Git object. It is still just a ref. §  Local topic branch names, remote tracking branch names, and tag names are all refs.
  27. 27. Symrefs HEAD ORIG_HEAD
  28. 28. Symrefs HEAD Always refers to the most recent commit on the current branch. When you change branches, HEAD is updated to refer to the new branch’s latest commit.
  29. 29. Symrefs ORIG_HEAD Certain operations, such as merge and reset, record the previous version of HEAD in ORIG_HEAD just prior to adjusting it to a new value. You can use ORIG_HEAD to recover or revert to the previous state or to make a comparison.
  30. 30. Relative Commit Names Git provides mechanism for identifying a commit relative to another reference: ^: One commit before (master^, master^^, HEAD^,etc) ~: N commits before (master~2, HEAD~4)
  31. 31. Relative Commit Names C  is  a  commit   C^^     C~3   C~1     C~2   C^               git  show-­‐branch  -­‐-­‐more=35   C  
  32. 32. COMMITS
  33. 33. What is a commit A commit is used to record changes to a repository. When a commit occurs, Git records a “snapshot” of the index and places that snapshot in the object store.
  34. 34. Format $ git commit -m “Message” $ git commit -am “Message” $ git commit -m “Message” <file> $ git commit --amend
  35. 35. Example of use: --amend Fixing a typo
  36. 36. Commit history You can see the history of commits: $ git log (same as git log HEAD) $ git log <commit-name>: The log starts at the named commit. E.g: $ git log master
  37. 37. Commit history Specify a commit range (since..until) $ git log master~12..master~10 Show only commits for a path $ git log -- <path> E.g. git log -- README3.txt
  38. 38. Commit history Show commits with a regular expression $ git log --grep=‘reg-exp’ --no-merges: Removes merge commits Show changes during a time $ git log --since --before --after=“2010-04-18”
  39. 39. FIXING COMMITS
  40. 40. Fixing commits Flow 1. Discard changes in a file in the index to the copy in working directory $ git checkout -- <files> 2. Reverting a file some commits before $ git checkout <commit-id> file
  41. 41. Basic Flow: Reset You can reset some status of your repository: $ git reset $ git reset HEAD <file> $ git reset --soft <commit-id> $ git reset --hard <commit-id> $ git reset --mixed <commit-id>
  42. 42. Basic Flow: Reset Working  Area   Index   Local  Repository   git  add  <files>   git  commit   git  reset  -­‐-­‐soQ  HEAD^   git  rm  -­‐-­‐cached  <file>   git  reset  HEAD  <file>   git  checkout  -­‐-­‐  <file>   git  reset  -­‐-­‐mixed  HEAD^  
  43. 43. Revert Undoes a committed snapshot but instead of removing the commit appends a new commit undoing changes introduced by the commit. This prevents losing history from Git. 1   2   3   4   git revert <commit>
  44. 44. Revert vs Reset Revert undoes a single commit, it does not “revert” back to the previous state of a project. 1   2   3   4   git  revert   1   2   3   4   git  reset  
  45. 45. Example of use: reset Premature commits in a branch
  46. 46. Rebasing interactive git rebase –i <commit-base> Alter individual commits removing, splitting and altering an existing series of commits.
  47. 47. Example of use Squashing Split Change commits in your past history
  48. 48. Preguntas Israel  Alcázar       @ialcazar  

×