Presented By:
Md Swawibe Ul Alam
Junior Software Engineer
Nascenia Limited
Merge
Git Merge
 What it does?
Join two or more development histories/branches
together
Git merge is 2 types:
 Fast forward
 No fast forward
Example : Fast-Forward Git Merge
 Let us assume that I created a topic
branch named speedup from the
current master. After working on this
branch for a while (three commits,
those white circles),I finally decided
that I am done and then I pushed it to
my own remote. Meanwhile, nothing
else happened in the master branch.
 Now if we use git merge using git fast-
forward then my work is landed on
the source tree. Because master has
not been changed since the commit
(gray circle).whole series of the
commits will be linear.
Example : Fast-Forward Git Merge
Example : No Fast-Forward Git Merge
 If we use -no-ff option (it stands for no
fast-forward). In this case, the history
looks slightly different (right side),
there is an additional commit (dotted
circle) emphasizing the merge
Rebase
Git Revert
 This command creates a new commit that undoes
the changes from a previous commit. This command
adds new history to the project (it doesn't modify
existing history)
 Use this to rollback changes you have committed
Git checkout
 Use this to checkout a branch or specific commit
 This will rollback any changes you have in your
working copy
 This will NOT make any changes to the history
Git reset
 Use this to rollback changes made to the index (eg:
from git add), which will NOT change the history.
 Use this to change what commit a head is pointing
to, which will change the history
Cherry Pick
 What git cherry-pick does, basically, is take a
commit from somewhere else, and "play it back"
wherever you are right now. Because this introduces
the same change with a different parent, Git builds a
new commit with a different ID
Cherry Pick : Example
❖ If you were at node H in this graph, and you typed git Cherry-pick E you'd
wind up with a copy of commit E—let's call it "E prime" or E'—that
pointed to H as its parent
❖ if you typed something like git cherry-pick C D E
Advanced Git Log
Advanced git log can be divided into two parts :
Formating log output
Filtering log output
Formating log output
 Formatting shows how each commit is displayed. Available
formats are-
 Oneline
 Decorating
 Diffs
 Shortlog
 Graph
 Custom formatting
Oneline
 The --oneline flag condenses each commit to a single
line.
 $ git log --oneline
 output:
0e25143 Merge branch 'feature'
ad8621a Fix a bug in the feature
16b36c6 Add a new feature
23ad9ad Add the initial code base
Decorating
 The --decorate flag makes git log display all of the
references (e.g., branches, tags, etc) that point to
each commit.
 $ git log --oneline --decorate
 output:
0e25143 (HEAD, master) Merge branch 'feature'
ad8621a (feature) Fix a bug in the feature
16b36c6 Add a new feature
23ad9ad (tag: v0.9) Add the initial code base
Diffs
 The git log command includes many options for displaying diffs with each
commit. Two of the most common options are -
 --stat
 The --stat option displays the number of insertions and deletions to each file altered by
each commit
 $ git log --stat
 output:
 commit f2a238924e89ca1d4947662928218a06d39068c3
Author: John <john@example.com>
Date: Fri Jun 25 17:30:28 2014 -0500
Add a new feature
hello.py | 105 ++++++++++++++++++++++++-----------------
1 file changed, 67 insertion(+), 38 deletions(-)
Diffs cont..
 -p
 To see the actual changes introduced by each commit, pass the -p option
to git log
 $ git log --stat -p
 output:
 commit 16b36c697eb2d24302f89aa22d9170dfe609855b
Author: Mary <mary@example.com>
Date: Fri Jun 25 17:31:57 2014 -0500
Fix a bug in the feature
diff --git a/hello.py b/hello.py
index 18ca709..c673b40 100644
--- a/hello.py
+++ b/hello.py
@@ -13,14 +13,14 @@ B
-print("Hello, World!")
+print("Hello, Git!")
Shortlog
 The git shortlog command is a special version of git
log intended for creating release announcements.
 It groups each commit by author and displays the
first line of each commit message
Shortlog cont..
$ git shortlog
output:
Mary (2):
Fix a bug in the feature
Fix a serious security hole in our framework
John (3):
Add the initial code base
Add a new feature
Merge branch 'feature'
Graph
 The --graph option draws an ASCII graph
representing the branch structure of the commit
history
 This is commonly used in conjunction with the --
oneline and --decorate
Graph cont..
$ git log --graph --oneline --decorate
output:
* 0e25143 (HEAD, master) Merge branch 'feature'
|
| * 16b36c6 Fix a bug in the new feature
| * 23ad9ad Start a new feature
* | ad8621a Fix a critical security issue
|/
* 400e4b7 Fix typos in the documentation
* 160e224 Add the initial code base
Custom formatting
 For all of your other git log formatting needs the --
pretty=format:"<string>" option.
 Display each commit however we want using printf-
style placeholders
Custom formatting cont
$ git log --pretty=format:"%cn committed %h on %cd"
output:
John committed 400e4b7 on Fri Jun 24 12:30:04 2014 -0500
John committed 89ab2cf on Thu Jun 23 17:09:42 2014 -0500
Mary committed 180e223 on Wed Jun 22 17:21:19 2014 -0500
John committed f12ca28 on Wed Jun 22 13:50:31 2014 -0500
Filtering Log Output
 Filtering shows which commits are included in the
output. Following commands are used for filtering-
 By Amount
 $ git log -3
 By Date
 $ git log --after="2014-7-1"
 $ git log --after="yesterday"
 $ git log --after="2014-7-1" --before="2014-7-4"
Filtering Log Output Cont..
 By Author
 $ git log --author="John"
 $ git log --author="John|Mary" //(Mary or John)
 By Message
 $ git log --grep="JRA-224:"
 By File
 git log -- foo.py bar.py
 By Content
 git log -S"Hello, World!"
Filtering Log Output Cont..
 By Range
 $ git log master..feature
 $ git log <since>..<until>
 Filtering Merge Commits
 $ git log --no-merges
 $ git log --merges
Md Swawibe Ul Alam

Advanced Git Presentation By Swawibe

  • 1.
    Presented By: Md SwawibeUl Alam Junior Software Engineer Nascenia Limited
  • 2.
  • 3.
    Git Merge  Whatit does? Join two or more development histories/branches together
  • 7.
    Git merge is2 types:  Fast forward  No fast forward
  • 8.
    Example : Fast-ForwardGit Merge  Let us assume that I created a topic branch named speedup from the current master. After working on this branch for a while (three commits, those white circles),I finally decided that I am done and then I pushed it to my own remote. Meanwhile, nothing else happened in the master branch.
  • 9.
     Now ifwe use git merge using git fast- forward then my work is landed on the source tree. Because master has not been changed since the commit (gray circle).whole series of the commits will be linear. Example : Fast-Forward Git Merge
  • 10.
    Example : NoFast-Forward Git Merge  If we use -no-ff option (it stands for no fast-forward). In this case, the history looks slightly different (right side), there is an additional commit (dotted circle) emphasizing the merge
  • 12.
  • 22.
    Git Revert  Thiscommand creates a new commit that undoes the changes from a previous commit. This command adds new history to the project (it doesn't modify existing history)  Use this to rollback changes you have committed
  • 23.
    Git checkout  Usethis to checkout a branch or specific commit  This will rollback any changes you have in your working copy  This will NOT make any changes to the history
  • 24.
    Git reset  Usethis to rollback changes made to the index (eg: from git add), which will NOT change the history.  Use this to change what commit a head is pointing to, which will change the history
  • 25.
    Cherry Pick  Whatgit cherry-pick does, basically, is take a commit from somewhere else, and "play it back" wherever you are right now. Because this introduces the same change with a different parent, Git builds a new commit with a different ID
  • 26.
  • 27.
    ❖ If youwere at node H in this graph, and you typed git Cherry-pick E you'd wind up with a copy of commit E—let's call it "E prime" or E'—that pointed to H as its parent
  • 28.
    ❖ if youtyped something like git cherry-pick C D E
  • 29.
    Advanced Git Log Advancedgit log can be divided into two parts : Formating log output Filtering log output
  • 30.
    Formating log output Formatting shows how each commit is displayed. Available formats are-  Oneline  Decorating  Diffs  Shortlog  Graph  Custom formatting
  • 31.
    Oneline  The --onelineflag condenses each commit to a single line.  $ git log --oneline  output: 0e25143 Merge branch 'feature' ad8621a Fix a bug in the feature 16b36c6 Add a new feature 23ad9ad Add the initial code base
  • 32.
    Decorating  The --decorateflag makes git log display all of the references (e.g., branches, tags, etc) that point to each commit.  $ git log --oneline --decorate  output: 0e25143 (HEAD, master) Merge branch 'feature' ad8621a (feature) Fix a bug in the feature 16b36c6 Add a new feature 23ad9ad (tag: v0.9) Add the initial code base
  • 33.
    Diffs  The gitlog command includes many options for displaying diffs with each commit. Two of the most common options are -  --stat  The --stat option displays the number of insertions and deletions to each file altered by each commit  $ git log --stat  output:  commit f2a238924e89ca1d4947662928218a06d39068c3 Author: John <john@example.com> Date: Fri Jun 25 17:30:28 2014 -0500 Add a new feature hello.py | 105 ++++++++++++++++++++++++----------------- 1 file changed, 67 insertion(+), 38 deletions(-)
  • 34.
    Diffs cont..  -p To see the actual changes introduced by each commit, pass the -p option to git log  $ git log --stat -p  output:  commit 16b36c697eb2d24302f89aa22d9170dfe609855b Author: Mary <mary@example.com> Date: Fri Jun 25 17:31:57 2014 -0500 Fix a bug in the feature diff --git a/hello.py b/hello.py index 18ca709..c673b40 100644 --- a/hello.py +++ b/hello.py @@ -13,14 +13,14 @@ B -print("Hello, World!") +print("Hello, Git!")
  • 35.
    Shortlog  The gitshortlog command is a special version of git log intended for creating release announcements.  It groups each commit by author and displays the first line of each commit message
  • 36.
    Shortlog cont.. $ gitshortlog output: Mary (2): Fix a bug in the feature Fix a serious security hole in our framework John (3): Add the initial code base Add a new feature Merge branch 'feature'
  • 37.
    Graph  The --graphoption draws an ASCII graph representing the branch structure of the commit history  This is commonly used in conjunction with the -- oneline and --decorate
  • 38.
    Graph cont.. $ gitlog --graph --oneline --decorate output: * 0e25143 (HEAD, master) Merge branch 'feature' | | * 16b36c6 Fix a bug in the new feature | * 23ad9ad Start a new feature * | ad8621a Fix a critical security issue |/ * 400e4b7 Fix typos in the documentation * 160e224 Add the initial code base
  • 39.
    Custom formatting  Forall of your other git log formatting needs the -- pretty=format:"<string>" option.  Display each commit however we want using printf- style placeholders
  • 40.
    Custom formatting cont $git log --pretty=format:"%cn committed %h on %cd" output: John committed 400e4b7 on Fri Jun 24 12:30:04 2014 -0500 John committed 89ab2cf on Thu Jun 23 17:09:42 2014 -0500 Mary committed 180e223 on Wed Jun 22 17:21:19 2014 -0500 John committed f12ca28 on Wed Jun 22 13:50:31 2014 -0500
  • 41.
    Filtering Log Output Filtering shows which commits are included in the output. Following commands are used for filtering-  By Amount  $ git log -3  By Date  $ git log --after="2014-7-1"  $ git log --after="yesterday"  $ git log --after="2014-7-1" --before="2014-7-4"
  • 42.
    Filtering Log OutputCont..  By Author  $ git log --author="John"  $ git log --author="John|Mary" //(Mary or John)  By Message  $ git log --grep="JRA-224:"  By File  git log -- foo.py bar.py  By Content  git log -S"Hello, World!"
  • 43.
    Filtering Log OutputCont..  By Range  $ git log master..feature  $ git log <since>..<until>  Filtering Merge Commits  $ git log --no-merges  $ git log --merges
  • 44.