SlideShare a Scribd company logo
1 of 32
GIT
COMMANDES ET MEMENTO
@ElZakaria
 Set up your information, really important.
$ git config --global user.name ‘’ElZakaria"
$ git config --global user.email preemptif@gmail.com

If you want to override this with a different name
or e-mail address for specific projects, you can
run the command without the --global option
when you’re in that project.

YOUR IDENTITY!!!!
Now that your identity is set up, you can
configure the default text editor that will
be used when Git needs you to type in a
message. By default, Git uses your
system’s default editor
$ git config --global core.editor emacs


$git config --list to Check your settings.
$ git config user.name to check for a specific key

See some configs values


If you ever need help while using Git,
there are three ways to get the manual
page (manpage) help for any of the Git
commands:

$ git help <verb>
 $git <verb> --help
 $man git-<verb>


Linux

Wanna get some help? [RTFM]


The main tool you use to determine which
files are in which state is the git status
command.
$ git status # On branch master
…..

If any change to the TRACKED files are done,
it will be show there before commiting them!

Check the status of your files


When you clone a repo, all the files are by
default tracked, but adding new ones are not
tracked even if is added since the last
snapshot, you should do it explicitly:

$ git add MyFile.txt
The git add command takes a path name for
either a file or a directory; if it’s a directory,
the command adds all the files in that
directory recursively.

Begin to track a new File
FOLDER
(Working
Directory)

add

Index
(Staging
Area)

git add command (it’s a multipurpose
command —
you use it to begin tracking new
files, to stage files,
and to do other things like marking
merge-conflicted
files as resolved).

commit

HEAD

Trees maintained by GIT!


To see what you’ve changed but not yet
staged, type git diff with no other
arguments:
$ git diff
diff --git a/MYFILE.txt b/MYFILE.txt
index 778f824..ab9e1ea 100644
--- a/MYFILE.txt
+++ b/MYFILE.txt
@@ -1,3 +1,4 @@
content added!
Oups forgot this sentence
-Once again, sorry I had a terrible morning
 No newline at end of file
+Once again, sorry I had a terrible morning
+m
 No newline at end of file

Details: Changed and not staged


If you want to see what you’ve staged
that will go into your next commit, you
can use git diff --cached. (In Git versions
1.6.1 and later, you can also use git diff -staged, which may be easier to
remember.) This command compares your
staged changes to your last commit:
$git diff --staged

Details: changed AND Staged


To commit what you’ve changed:

$git commit
OR
$git commit –m ‘’ Description message ‘’
OR
Put the diff in
description
$git commit …. -v
ElZakaria@ELDEV ~/projet1 (master)
$ git commit -m "Mon changement à Moi"
[master 54d99c0] Mon changement à Moi
1 file changed, 5 insertions(+)
create mode 100644 MYFILE.txt

SHA-1
Checksum’s
Commit

Commiting the changes locally.
$git commit –a –m ‘’blah blah blah’’


Providing the -a option to the git commit
command makes Git automatically stage
every file that is already tracked before
doing the commit, letting you skip the
git add part.

Skipping the Staging Area
If you simply remove the file from your working
directory, it shows up under the “Changes not
staged for commit”
You have to add it $git add …
Now you may want to use git rm to don’t track it:
$git rm MYFILE.TXT


If you modified the file and added it to the index
already, you must force the removal with the -f
option. This is a safety feature to prevent
accidental removal of data that hasn’t yet been
recorded in a snapshot and that can’t be
recovered from Git.


Another useful thing you may want to do
is to keep the file in your working tree but
remove it from your staging area.

$ git rm --cached readme.txt



You can pass files, directories, and fileglob patterns to the git rm command!!!

KEEP The file, remove from index
$git mv file_FROM file_TO
Same as...

$ mv README.txt README
$ git rm README.txt
$ git add README

Moving Files with GIT


After you have created several commits,
or if you have cloned a repository with an
existing commit history, you’ll probably
want to look back to see what has
happened. The most basic and powerful
tool to do this is the git log command.
$git log

Viewing the commit History


A huge number and variety of options.



One of the more helpful options is -p, which shows
the diff introduced in each commit. You can also
use -2, which limits the output to only the last two
entries

$git log –p -2

$git log --word-diff

Difference in
words not lines!

$git log -–stat
The --stat option prints below each commit entry a list of modified files,
how many files were changed, and how many lines in those files were
added and removed. It also puts a summary of the information at the
end.
Short
Full
fuller
oneline

$ git log --pretty=oneline
$ git log --pretty=oneline
ca82a6dff817ec66f44342007202690a93763949 changed the verison number
085bb3bcb608e1e8451d4b2432f8ecbe6306e7e7 removed unnecessary test code
a11bef06a3f659402fe7563abf99ad00de2209e6 first commit

$ git log --pretty=format:"%h - %an, %ar : %s"
ca82a6d - Scott Chacon, 11 months ago : changed the version number
085bb3b - Scott Chacon, 11 months ago : removed unnecessary test code
a11bef0 - Scott Chacon, 11 months ago : first commit

Descendant
order

Formatting the commit History
Most useful option for format
P.S : --graph option is also interesting [Branch and merges…]

Most useful option for format


-(n) : Show only the last n commits



--since, --after : Limit the commits to
those made after the specified date.
$ git log --since=2.weeks

This command works with lots of formats
— you can specify a specific date (“200801-15”) or a relative date such as “2
years 1 day 3 minutes ago”.

Limiting Log Output


--author : allows you to filter on a specific
author.



--grep : lets you search for keywords in the
commit messages.

Note :
if you want to specify both author and grep
options, you have to add --all-match or the
command will match commits with either.
Others: --commiter: ….

Limiting Log Output


Gitk is basically a visual git log tool, and it
accepts nearly all the filtering options that
git log does. If you type gitk on the
command line in your project:

Gitk accept nearly all filtering git log options!

See logs visually!


One of the common undos takes place when
you commit too early and possibly forget to
add some files, or you mess up your commit
message.
$ git commit --amend

$ git commit -m 'initial commit'
$ git add forgotten_file
$ git commit --amend

Changing Your Last Commit
# Changes to be committed:
 # (use "git reset HEAD <file>..." to
unstage) #
 # modified: README.txt
 # modified: benchmarks.rb


git reset HEAD benchmarks.rb

Unstaging a staged file
# 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: benchmarks.rb #










$ git checkout -- benchmarks.rb
$ git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage) #
# modified: README.txt

Discard the changes


Anything that is committed in Git can
almost always be recovered. Even
commits that were on branches that were
deleted or commits that were overwritten
with an --amend commit can be
recovered.



Anything you lose that was never
committed is likely never to be seen
again.

YOU Should Understand this


To see which remote servers you have
configured, you can run the git remote
command. It lists the shortnames of each
remote handle you’ve specified.
$ git remote
origin

$ git remote -v
origin git://github.com/schacon/ticgit.git
(fetch)
origin git://github.com/s…/ticgit.git (push)

Showing Your Remotes
$ git remote add pb
git://github.com/paulboone/ticgit.git

shortname

$ git remote -v
origin git://github.com/schacon/ticgit.git
pb git://github.com/paulboone/ticgit.git
$git remote add [shortname] [url]

Adding remote repositories
$ git fetch [remote-name]
Goes to the server and get any new work, but
doesn’t merge anything, you have to do it
manually!
If you have a branch set up to track a remote
branch, you can use the git pull command to
automatically fetch and then merge a
remote branch into your current branch.
$git pull [remote-name]

Fetching and pulling from remotes
$git push [remote-name] [branch-name]
$ git push origin master
This command works only if you cloned from a
server to which you have write access and if
nobody has pushed in the meantime. If you
and someone else clone at the same time and
they push upstream and then you push
upstream, your push will rightly be rejected.
You’ll have to pull down their work first and
incorporate it into yours before you’ll be
allowed to push.

Push to the server
$ git remote show origin
• remote origin URL:
git://github.com/schacon/ticgit.git
Remote branch merged with 'git pull'
while on branch master
master
Tracked remote branches
master
ticgit

Inspecting a remote
$ git remote rename pb paul
$ git remote
origin
Paul
$ git remote rm paul
$ git remote
origin

Removing and Renaming Remotes

More Related Content

What's hot (13)

Tech thursdays / GIT
Tech thursdays / GITTech thursdays / GIT
Tech thursdays / GIT
 
Exprimiendo GIT
Exprimiendo GITExprimiendo GIT
Exprimiendo GIT
 
Sacándole jugo a git
Sacándole jugo a gitSacándole jugo a git
Sacándole jugo a git
 
15 3. modulization
15 3. modulization15 3. modulization
15 3. modulization
 
GIT_GITHUB_2016_06_17
GIT_GITHUB_2016_06_17GIT_GITHUB_2016_06_17
GIT_GITHUB_2016_06_17
 
Command cheatsheets mac
Command cheatsheets macCommand cheatsheets mac
Command cheatsheets mac
 
Command cheatsheets windows
Command cheatsheets windowsCommand cheatsheets windows
Command cheatsheets windows
 
Windows Cheatsheet
Windows CheatsheetWindows Cheatsheet
Windows Cheatsheet
 
Pengenalan Git
Pengenalan GitPengenalan Git
Pengenalan Git
 
Mac Linux Commands cheatsheet
Mac Linux Commands cheatsheetMac Linux Commands cheatsheet
Mac Linux Commands cheatsheet
 
Git a stupid change tracker and persistent map.
Git a stupid change tracker and persistent map.Git a stupid change tracker and persistent map.
Git a stupid change tracker and persistent map.
 
HackMTY - GitHub Workshop
HackMTY - GitHub WorkshopHackMTY - GitHub Workshop
HackMTY - GitHub Workshop
 
Linux Command For Beginners 6 - copy commands for linux | BUET Pattern Job Pr...
Linux Command For Beginners 6 - copy commands for linux | BUET Pattern Job Pr...Linux Command For Beginners 6 - copy commands for linux | BUET Pattern Job Pr...
Linux Command For Beginners 6 - copy commands for linux | BUET Pattern Job Pr...
 

Viewers also liked (7)

Git Introduction
Git IntroductionGit Introduction
Git Introduction
 
Git - Introduction and Overview
Git - Introduction and OverviewGit - Introduction and Overview
Git - Introduction and Overview
 
Basic Git commands
Basic Git commandsBasic Git commands
Basic Git commands
 
git command
git commandgit command
git command
 
Basics About Git & GitHub
Basics About Git & GitHubBasics About Git & GitHub
Basics About Git & GitHub
 
Version control system
Version control systemVersion control system
Version control system
 
A practical approach to version control for SQL Server - By Steve Jones
A practical approach to version control for SQL Server - By Steve JonesA practical approach to version control for SQL Server - By Steve Jones
A practical approach to version control for SQL Server - By Steve Jones
 

Similar to Git Memento of basic commands

Git 入门与实践
Git 入门与实践Git 入门与实践
Git 入门与实践
Terry Wang
 
Git 入门 与 实践
Git 入门 与 实践Git 入门 与 实践
Git 入门 与 实践
Terry Wang
 

Similar to Git Memento of basic commands (20)

Git Commands Every Developer Should Know?
Git Commands Every Developer Should Know?Git Commands Every Developer Should Know?
Git Commands Every Developer Should Know?
 
Git and Github
Git and GithubGit and Github
Git and Github
 
Git and github
Git and githubGit and github
Git and github
 
Git basics 2
Git basics 2Git basics 2
Git basics 2
 
Git github
Git githubGit github
Git github
 
Github By Nyros Developer
Github By Nyros DeveloperGithub By Nyros Developer
Github By Nyros Developer
 
Git and github 101
Git and github 101Git and github 101
Git and github 101
 
Hacktoberfest intro to Git and GitHub
Hacktoberfest intro to Git and GitHubHacktoberfest intro to Git and GitHub
Hacktoberfest intro to Git and GitHub
 
Introduction To Git Workshop
Introduction To Git WorkshopIntroduction To Git Workshop
Introduction To Git Workshop
 
Git
GitGit
Git
 
Mastering git - Workflow
Mastering git - WorkflowMastering git - Workflow
Mastering git - Workflow
 
DrupalCafe5 VCS
DrupalCafe5 VCSDrupalCafe5 VCS
DrupalCafe5 VCS
 
Git commands
Git commandsGit commands
Git commands
 
Git 入门与实践
Git 入门与实践Git 入门与实践
Git 入门与实践
 
Git
GitGit
Git
 
Git 入门 与 实践
Git 入门 与 实践Git 入门 与 实践
Git 入门 与 实践
 
Git introduction
Git introductionGit introduction
Git introduction
 
Pro git - grasping it conceptually
Pro git - grasping it conceptuallyPro git - grasping it conceptually
Pro git - grasping it conceptually
 
Git learning
Git learningGit learning
Git learning
 
GIT Basics
GIT BasicsGIT Basics
GIT Basics
 

More from Zakaria Bouazza

Présentation de RMI Java
Présentation de RMI JavaPrésentation de RMI Java
Présentation de RMI Java
Zakaria Bouazza
 

More from Zakaria Bouazza (7)

Glassfish 4 quick guide
Glassfish 4 quick guideGlassfish 4 quick guide
Glassfish 4 quick guide
 
Page viewer sous android
Page viewer sous androidPage viewer sous android
Page viewer sous android
 
Action bar sous Android
Action bar sous AndroidAction bar sous Android
Action bar sous Android
 
Success insights
Success insightsSuccess insights
Success insights
 
Méthodologie 2 Track Unified Process
Méthodologie 2 Track Unified ProcessMéthodologie 2 Track Unified Process
Méthodologie 2 Track Unified Process
 
Brevets
BrevetsBrevets
Brevets
 
Présentation de RMI Java
Présentation de RMI JavaPrésentation de RMI Java
Présentation de RMI Java
 

Recently uploaded

會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
中 央社
 

Recently uploaded (20)

UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024
 
Pragya Champions Chalice 2024 Prelims & Finals Q/A set, General Quiz
Pragya Champions Chalice 2024 Prelims & Finals Q/A set, General QuizPragya Champions Chalice 2024 Prelims & Finals Q/A set, General Quiz
Pragya Champions Chalice 2024 Prelims & Finals Q/A set, General Quiz
 
HVAC System | Audit of HVAC System | Audit and regulatory Comploance.pptx
HVAC System | Audit of HVAC System | Audit and regulatory Comploance.pptxHVAC System | Audit of HVAC System | Audit and regulatory Comploance.pptx
HVAC System | Audit of HVAC System | Audit and regulatory Comploance.pptx
 
Championnat de France de Tennis de table/
Championnat de France de Tennis de table/Championnat de France de Tennis de table/
Championnat de France de Tennis de table/
 
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
 
Removal Strategy _ FEFO _ Working with Perishable Products in Odoo 17
Removal Strategy _ FEFO _ Working with Perishable Products in Odoo 17Removal Strategy _ FEFO _ Working with Perishable Products in Odoo 17
Removal Strategy _ FEFO _ Working with Perishable Products in Odoo 17
 
BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...
BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...
BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...
 
Operations Management - Book1.p - Dr. Abdulfatah A. Salem
Operations Management - Book1.p  - Dr. Abdulfatah A. SalemOperations Management - Book1.p  - Dr. Abdulfatah A. Salem
Operations Management - Book1.p - Dr. Abdulfatah A. Salem
 
“O BEIJO” EM ARTE .
“O BEIJO” EM ARTE                       .“O BEIJO” EM ARTE                       .
“O BEIJO” EM ARTE .
 
MichaelStarkes_UncutGemsProjectSummary.pdf
MichaelStarkes_UncutGemsProjectSummary.pdfMichaelStarkes_UncutGemsProjectSummary.pdf
MichaelStarkes_UncutGemsProjectSummary.pdf
 
demyelinated disorder: multiple sclerosis.pptx
demyelinated disorder: multiple sclerosis.pptxdemyelinated disorder: multiple sclerosis.pptx
demyelinated disorder: multiple sclerosis.pptx
 
size separation d pharm 1st year pharmaceutics
size separation d pharm 1st year pharmaceuticssize separation d pharm 1st year pharmaceutics
size separation d pharm 1st year pharmaceutics
 
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community PartnershipsSpring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
 
REPRODUCTIVE TOXICITY STUDIE OF MALE AND FEMALEpptx
REPRODUCTIVE TOXICITY  STUDIE OF MALE AND FEMALEpptxREPRODUCTIVE TOXICITY  STUDIE OF MALE AND FEMALEpptx
REPRODUCTIVE TOXICITY STUDIE OF MALE AND FEMALEpptx
 
Incoming and Outgoing Shipments in 2 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 2 STEPS Using Odoo 17Incoming and Outgoing Shipments in 2 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 2 STEPS Using Odoo 17
 
philosophy and it's principles based on the life
philosophy and it's principles based on the lifephilosophy and it's principles based on the life
philosophy and it's principles based on the life
 
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjStl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
 
Basic Civil Engineering notes on Transportation Engineering, Modes of Transpo...
Basic Civil Engineering notes on Transportation Engineering, Modes of Transpo...Basic Civil Engineering notes on Transportation Engineering, Modes of Transpo...
Basic Civil Engineering notes on Transportation Engineering, Modes of Transpo...
 
How to Analyse Profit of a Sales Order in Odoo 17
How to Analyse Profit of a Sales Order in Odoo 17How to Analyse Profit of a Sales Order in Odoo 17
How to Analyse Profit of a Sales Order in Odoo 17
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
 

Git Memento of basic commands

  • 2.  Set up your information, really important. $ git config --global user.name ‘’ElZakaria" $ git config --global user.email preemptif@gmail.com If you want to override this with a different name or e-mail address for specific projects, you can run the command without the --global option when you’re in that project. YOUR IDENTITY!!!!
  • 3. Now that your identity is set up, you can configure the default text editor that will be used when Git needs you to type in a message. By default, Git uses your system’s default editor $ git config --global core.editor emacs  $git config --list to Check your settings. $ git config user.name to check for a specific key See some configs values
  • 4.  If you ever need help while using Git, there are three ways to get the manual page (manpage) help for any of the Git commands: $ git help <verb>  $git <verb> --help  $man git-<verb>  Linux Wanna get some help? [RTFM]
  • 5.  The main tool you use to determine which files are in which state is the git status command. $ git status # On branch master ….. If any change to the TRACKED files are done, it will be show there before commiting them! Check the status of your files
  • 6.  When you clone a repo, all the files are by default tracked, but adding new ones are not tracked even if is added since the last snapshot, you should do it explicitly: $ git add MyFile.txt The git add command takes a path name for either a file or a directory; if it’s a directory, the command adds all the files in that directory recursively. Begin to track a new File
  • 7. FOLDER (Working Directory) add Index (Staging Area) git add command (it’s a multipurpose command — you use it to begin tracking new files, to stage files, and to do other things like marking merge-conflicted files as resolved). commit HEAD Trees maintained by GIT!
  • 8.  To see what you’ve changed but not yet staged, type git diff with no other arguments: $ git diff diff --git a/MYFILE.txt b/MYFILE.txt index 778f824..ab9e1ea 100644 --- a/MYFILE.txt +++ b/MYFILE.txt @@ -1,3 +1,4 @@ content added! Oups forgot this sentence -Once again, sorry I had a terrible morning No newline at end of file +Once again, sorry I had a terrible morning +m No newline at end of file Details: Changed and not staged
  • 9.  If you want to see what you’ve staged that will go into your next commit, you can use git diff --cached. (In Git versions 1.6.1 and later, you can also use git diff -staged, which may be easier to remember.) This command compares your staged changes to your last commit: $git diff --staged Details: changed AND Staged
  • 10.  To commit what you’ve changed: $git commit OR $git commit –m ‘’ Description message ‘’ OR Put the diff in description $git commit …. -v ElZakaria@ELDEV ~/projet1 (master) $ git commit -m "Mon changement à Moi" [master 54d99c0] Mon changement à Moi 1 file changed, 5 insertions(+) create mode 100644 MYFILE.txt SHA-1 Checksum’s Commit Commiting the changes locally.
  • 11. $git commit –a –m ‘’blah blah blah’’  Providing the -a option to the git commit command makes Git automatically stage every file that is already tracked before doing the commit, letting you skip the git add part. Skipping the Staging Area
  • 12. If you simply remove the file from your working directory, it shows up under the “Changes not staged for commit” You have to add it $git add … Now you may want to use git rm to don’t track it: $git rm MYFILE.TXT  If you modified the file and added it to the index already, you must force the removal with the -f option. This is a safety feature to prevent accidental removal of data that hasn’t yet been recorded in a snapshot and that can’t be recovered from Git.
  • 13.  Another useful thing you may want to do is to keep the file in your working tree but remove it from your staging area. $ git rm --cached readme.txt  You can pass files, directories, and fileglob patterns to the git rm command!!! KEEP The file, remove from index
  • 14. $git mv file_FROM file_TO Same as... $ mv README.txt README $ git rm README.txt $ git add README Moving Files with GIT
  • 15.  After you have created several commits, or if you have cloned a repository with an existing commit history, you’ll probably want to look back to see what has happened. The most basic and powerful tool to do this is the git log command. $git log Viewing the commit History
  • 16.  A huge number and variety of options.  One of the more helpful options is -p, which shows the diff introduced in each commit. You can also use -2, which limits the output to only the last two entries $git log –p -2 $git log --word-diff Difference in words not lines! $git log -–stat The --stat option prints below each commit entry a list of modified files, how many files were changed, and how many lines in those files were added and removed. It also puts a summary of the information at the end.
  • 17. Short Full fuller oneline $ git log --pretty=oneline $ git log --pretty=oneline ca82a6dff817ec66f44342007202690a93763949 changed the verison number 085bb3bcb608e1e8451d4b2432f8ecbe6306e7e7 removed unnecessary test code a11bef06a3f659402fe7563abf99ad00de2209e6 first commit $ git log --pretty=format:"%h - %an, %ar : %s" ca82a6d - Scott Chacon, 11 months ago : changed the version number 085bb3b - Scott Chacon, 11 months ago : removed unnecessary test code a11bef0 - Scott Chacon, 11 months ago : first commit Descendant order Formatting the commit History
  • 18. Most useful option for format
  • 19. P.S : --graph option is also interesting [Branch and merges…] Most useful option for format
  • 20.  -(n) : Show only the last n commits  --since, --after : Limit the commits to those made after the specified date. $ git log --since=2.weeks This command works with lots of formats — you can specify a specific date (“200801-15”) or a relative date such as “2 years 1 day 3 minutes ago”. Limiting Log Output
  • 21.  --author : allows you to filter on a specific author.  --grep : lets you search for keywords in the commit messages. Note : if you want to specify both author and grep options, you have to add --all-match or the command will match commits with either. Others: --commiter: …. Limiting Log Output
  • 22.  Gitk is basically a visual git log tool, and it accepts nearly all the filtering options that git log does. If you type gitk on the command line in your project: Gitk accept nearly all filtering git log options! See logs visually!
  • 23.  One of the common undos takes place when you commit too early and possibly forget to add some files, or you mess up your commit message. $ git commit --amend $ git commit -m 'initial commit' $ git add forgotten_file $ git commit --amend Changing Your Last Commit
  • 24. # Changes to be committed:  # (use "git reset HEAD <file>..." to unstage) #  # modified: README.txt  # modified: benchmarks.rb  git reset HEAD benchmarks.rb Unstaging a staged file
  • 25. # 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: benchmarks.rb #         $ git checkout -- benchmarks.rb $ git status # On branch master # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # modified: README.txt Discard the changes
  • 26.  Anything that is committed in Git can almost always be recovered. Even commits that were on branches that were deleted or commits that were overwritten with an --amend commit can be recovered.  Anything you lose that was never committed is likely never to be seen again. YOU Should Understand this
  • 27.  To see which remote servers you have configured, you can run the git remote command. It lists the shortnames of each remote handle you’ve specified. $ git remote origin $ git remote -v origin git://github.com/schacon/ticgit.git (fetch) origin git://github.com/s…/ticgit.git (push) Showing Your Remotes
  • 28. $ git remote add pb git://github.com/paulboone/ticgit.git shortname $ git remote -v origin git://github.com/schacon/ticgit.git pb git://github.com/paulboone/ticgit.git $git remote add [shortname] [url] Adding remote repositories
  • 29. $ git fetch [remote-name] Goes to the server and get any new work, but doesn’t merge anything, you have to do it manually! If you have a branch set up to track a remote branch, you can use the git pull command to automatically fetch and then merge a remote branch into your current branch. $git pull [remote-name] Fetching and pulling from remotes
  • 30. $git push [remote-name] [branch-name] $ git push origin master This command works only if you cloned from a server to which you have write access and if nobody has pushed in the meantime. If you and someone else clone at the same time and they push upstream and then you push upstream, your push will rightly be rejected. You’ll have to pull down their work first and incorporate it into yours before you’ll be allowed to push. Push to the server
  • 31. $ git remote show origin • remote origin URL: git://github.com/schacon/ticgit.git Remote branch merged with 'git pull' while on branch master master Tracked remote branches master ticgit Inspecting a remote
  • 32. $ git remote rename pb paul $ git remote origin Paul $ git remote rm paul $ git remote origin Removing and Renaming Remotes