Git Version Control Cookbook

"The cat-file command with the -p option prints the object given on the command line" ("Git's objects" section)

For a large project with thousands of files, I was interested in discovering which files within a directory were being tracked by my Git repository. My first step was to find the ID/SHA-1 of the directory, which was 7f21f0619053f44762c16a2707d845697e99a1f1. Then I ran the following command: git cat-file -p 7f21f0619053f44762c16a2707d845697e99a1f1. The result was the list of everything that was being tracked by Git, including both files and directories. Then I could conclude that anything that was present in that directory but that did not appear in the list returned by the command, was not being tracked by Git.

Created: 2018-10-18 00:43:12 Last updated: 2018-10-18 00:47:29

"How to do it...

1. The simplest way to see the history is to use the git log command; this will display the history in reverse chronological order. The output is paged through less and can be further limited, for example, by providing only the number of commits in the history to be displayed:

$ git log -3

2. This will display the following result:

commit 34acc370b4d6ae53f051255680feaefaf7f7850d
Author: John Doe <john.doe@example.com>
Date: Fri Dec 13 12:26:00 2013 +0100

This is the subject line of the commit message.

It should be followed by a blank line then the body, which is this text. Here
you can have multiple paragraphs etc. and explain your commit. It's like an
email with subject and body, so try to get people's attention in the subject

commit a90d1906337a6d75f1dc32da647931f932500d83
Author: John Doe <john.doe@example.com>
Date: Fri Dec 13 12:17:42 2013 +0100

Instructions for compiling hello_world.c

commit 485884efd6ac68cc7b58c643036acd3cd208d5c8
Merge: 44f1e05 0806a8b
Author: John Doe <john.doe@example.com>
Date: Fri Dec 13 12:14:49 2013 +0100

Merge branch 'feature/1'

Adds a hello world C program.
" ("Viewing the DAG, How to do it..." section)

I frequently use this command to see the history of the latest commits of the branch that I have currently checked out.

Created: 2019-01-31 21:36:42 Last updated: 2019-01-31 21:36:42

"How to do it...

  1. Start by listing all of the branches using the following command:

    $ git branch -a
    * develop
      remotes/origin/HEAD -> origin/develop
      remotes/origin/develop
      remotes/origin/feature/cities
      remotes/origin/feature/continents
      remotes/origin/feature/printing
      remotes/origin/master
      remotes/origin/release/1.0
  2. Let's try to fetch or pull and see whether anything happens, using the following command:

    $ git fetch
" ("Pruning remote branches" section)

I listed all of my branches:

C:\Users\jaimemontoya\[path]>git branch -a
  customersupport
  ericksreports
  fasterhelloworld
  fastersecondbackup
  fixaccounting
  fixgoogleanalytics
  fixgooglemodules
  fixjquery
  fixpagination
  googleanalytics
  improvenavigation
  jaimestagingarea
  jquery1.3.1toversion1.12.4
  jquery1.3.1toversion1.12.4update
  jquery1.3.1update
  jqueryupdate
  klaviyoemails
  latofontfamily
  master
  master123
  multiplephases
  multiplepanels
  multiplepanels20171129
  neighfrontend
  neighhtmlcss
  neighhtmlcssjs
  neighhtmlcssjscopy
  newcheckoutscreen
  newmasterbranch
  newmasterbranchphpfromsamanthai
  newmobilewebsite
  newmobilewebsitemerge
  purchasecongratulations
  readmorelinks
  recommendedforyourfriends
  recommendedforyourfriendstobuy
  satisfactionanalysis
  splittestforheader
  samanthaInewmobilewebsite
  samanthaimprovemenus
  samanthairecommendedforyourfriends
  samanthamaster123
  samanthamultiplepanels
  samanthamultiplepanels20171025
  samanthaneigh
* samanthaneighhtmlcssjs
  samanthawifi
  surveys
  testimonialspage
  testimonialspageboxes
  upsellcampaign
  upsellcampaignfromsamanthai
  remotes/origin/HEAD -> origin/master
  remotes/origin/MIT
  remotes/origin/alternativedesign
  remotes/origin/authorizations
  remotes/origin/bonusmegapoints
  remotes/origin/cartforcheckoutpage
  remotes/origin/cashfromkiosk
  remotes/origin/cleanup20131206
  remotes/origin/contactgroupsforemails
  remotes/origin/couponrestrictions
  remotes/origin/customersupport
  remotes/origin/dailyemails
  remotes/origin/emailfacebook
  remotes/origin/ericksreports
  remotes/origin/facebookopen
  remotes/origin/facebooksdk
  remotes/origin/fasterhelloworld
  remotes/origin/fastersecondbackup
  remotes/origin/fcmobilesite
  remotes/origin/fixgoogleanalytics
  remotes/origin/fixgooglemodules
  remotes/origin/fixjquery
  remotes/origin/fixpagination
  remotes/origin/freeproducts
  remotes/origin/googleanalytics
  remotes/origin/improvenavigation
  remotes/origin/jquery1.3.1toversion1.12.4update
  remotes/origin/jquery1.3.1update
  remotes/origin/klaviyoemails
  remotes/origin/latofontfamily
  remotes/origin/master
  remotes/origin/mobileversion
  remotes/origin/multiplepanels
  remotes/origin/neighfrontend
  remotes/origin/neighhtmlcss
  remotes/origin/neighhtmlcssjs
  remotes/origin/newchatroom
  remotes/origin/newcheckoutscreen
  remotes/origin/newdesignforhomepage
  remotes/origin/newdesignforhomepage2
  remotes/origin/newdesignforhomepagealternative
  remotes/origin/newmasterbranch
  remotes/origin/newmobilewebsite
  remotes/origin/newmobilewebsitemerge
  remotes/origin/purchasecongratulations
  remotes/origin/readmorelinks
  remotes/origin/recommendedforyourfriends
  remotes/origin/recommendedforyourfriendstobuy
  remotes/origin/refer_a_customer
  remotes/origin/referralsystem
  remotes/origin/refunded_products
  remotes/origin/returnedproducts
  remotes/origin/satisfactionanalysis
  remotes/origin/splittestforheader
  remotes/origin/samanthaInewmobilewebsite
  remotes/origin/samanthamultiplepanels20171025
  remotes/origin/samanthaneighhtmlcssjs
  remotes/origin/test_buying_products
  remotes/origin/test_js_forms
  remotes/origin/testimonialspage
  remotes/origin/testimonialspageboxes
  remotes/origin/upsellcampaign
  remotes/origin/useditemsquestionnaire
  remotes/samanthaI/GaReporting
  remotes/samanthaI/MIT
  remotes/samanthaI/alternates
  remotes/samanthaI/authorizations
  remotes/samanthaI/bonusmegapoints
  remotes/samanthaI/cartforcheckoutpage
  remotes/samanthaI/cashfromkiosk
  remotes/samanthaI/changeemail
  remotes/samanthaI/cleanup20131206
  remotes/samanthaI/contactgroupsforemails
  remotes/samanthaI/couponrestrictions
  remotes/samanthaI/dailyemails
  remotes/samanthaI/emailfacebook
  remotes/samanthaI/facebookopen
  remotes/samanthaI/facebooksdk
  remotes/samanthaI/fcmobilesite
  remotes/samanthaI/fixaccounting
  remotes/samanthaI/fixgoogleanalytics
  remotes/samanthaI/freeproducts
  remotes/samanthaI/improvenavigation
  remotes/samanthaI/jquery1.3.1toversion1.12.4update
  remotes/samanthaI/klaviyo
  remotes/samanthaI/latofontfamily
  remotes/samanthaI/master
  remotes/samanthaI/master123
  remotes/samanthaI/mobileversion
  remotes/samanthaI/multiplepanels
  remotes/samanthaI/neigh
  remotes/samanthaI/neighhtmlcssjs
  remotes/samanthaI/newFirebase
  remotes/samanthaI/newchatroom
  remotes/samanthaI/newcheckoutscreen
  remotes/samanthaI/newdesignforhomepage
  remotes/samanthaI/newdesignforhomepage2
  remotes/samanthaI/newdesignforhomepagealternative
  remotes/samanthaI/newmasterbranch
  remotes/samanthaI/newmobilewebsite
  remotes/samanthaI/newmobilewebsitegpp
  remotes/samanthaI/receiptAdds
  remotes/samanthaI/recommendedforyourfriends
  remotes/samanthaI/refer_a_customer
  remotes/samanthaI/referralsystem
  remotes/samanthaI/refunded_products
  remotes/samanthaI/returnedproducts
  remotes/samanthaI/samanthawifi
  remotes/samanthaI/samanthawifi222
  remotes/samanthaI/test_buying_products
  remotes/samanthaI/test_js_forms
  remotes/samanthaI/upsellcampaign
  remotes/samanthaI/useditemsquestionnaire
  remotes/samanthaI/voidrefundforfraud
C:\Users\jaimemontoya\[path]>git fetch samanthaI
webmaster@jaimemontoya's password:
remote: Enumerating objects: 250, done.
remote: Counting objects: 100% (236/236), done.
remote: Compressing objects: 100% (202/202), done.
remote: Total 202 (delta 151), reused 0 (delta 0)
Receiving objects: 100% (202/202), 332.06 KiB | 0 bytes/s, done.
Resolving deltas: 100% (151/151), completed with 26 local objects.
From ssh://jaimemontoya.com/~samanthaI/public_html/public
   ba4b8ce..8a2234d neighhtmlcssjs -> samanthaI/neighhtmlcssjs
   9932a22..e874b2a master123 -> samanthaI/master123

Created: ? Last updated: ?

Top