Skip to content

Instantly share code, notes, and snippets.

@KhaledMohamedP
Last active October 9, 2015 20:45
Show Gist options
  • Save KhaledMohamedP/b5eba5064b46858c3d46 to your computer and use it in GitHub Desktop.
Save KhaledMohamedP/b5eba5064b46858c3d46 to your computer and use it in GitHub Desktop.
GitHub Reference

About Git

Table of Contact

  1. [What is git?](#what is git?)
  2. Source

What is git?

version control group that saves changes into your files e.g Local Version Control (Database on local computer ) Centralized Version Control (Shared Server) Distributed Version Control (Both server and local)

File transition between 3 states

  1. Modified Files
  2. Staged Files
  3. Committed Files

Let's start

Change setting to keep track of changes based on users

git config --global user.name "your name"
git config --global user.email your@mail.com
git config --global core.editor "<subl/vi/..> -n -w"

Change editor to vim

git config --global core.editor "vim"

Present all the setting

git config --list 

Get help using the man

git help add 

Initialize a repository

git init

Add specific type of files to add to your repo

git add *.java 

assigning remote repo

git remote add origin <linkhere>

pushing your repo

git push -u origin master

Ignore certain files

you need to create a file [.gitignore] e.g *.jar //ignore all .jar files in your repo

Staging

git diff  //it should shows exactly what has been changed 
git diff --cached 

How to git commit?

Tip: Your commit heading should be 50 char or less explaining the reason why your commited Then you need paragraph format to explain the following

  1. Original problem that was address
  2. Specifier change that you've made
  3. The result of your change
  4. Future improvement
  5. Any known bug solved bug ID# ....
git commit -a -m 'changed something'   //this is to make changes quickly 

Log Commit History

a. git log # Shows all of the previous commit messages in reverse order

b. git log --pretty=oneline # Shows commits on one line

c. git log --pretty=format:"%h : %an : %ar : %s" 

I. %h - Abbreviated Hash  

II. %an - Authors Name

III. %ar - Date Changed

IV. %s - First Line of Comment

d. git log -p -2 # Shows the last 2 commit changes

e. git log --stat # Prints abbreviated stats

f. git log --since=1.weeks # Show only changes in the last week

g. git log --since="2014-04-12" # Show changes since this date

h. git log --author="Derek Banas" # Changes made by author

i. git log --before="2014-04-13" # Changes made before this date

Source

1-by Derek Banas

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment