Git Notes
Git Notes
Git Notes
Git Index:
==========
1. Introduction to git
2. Terminology
3. Repo
4. gitignore
5. logs
6. Branching
7. Merging
8. stash
9. unstaging(rm, reset, revert)
10. Tags
11. bisect
12. HEAD
13. Hooks
14. git-hub
Git Terminology:-
=================
1. client/server
2. workspace: - space where the client comm with server
3. Repository : - it is a container/Directory. for each product/project we've one
repository in the server.
4. Branch :- parallel development
5. Checkin:- Once the changes done, storing back to the server to maintain
perminentaly
6 Checkout:- Taking petmission from server to do modifications.
7. Revision/Version id/commit id : - git will track all the info of changes done by
a user like when,which repo,who,which file, what changes)
it stores in the form of snapshots i.e diff b/n existing file data and currently
modified file data.
commit id/check in :- with 40 char long
in workspace we've 3 stages before commit id get generated
--> working dir:- where you working with files physically
--> Staging Area:- it helps to create commit id(it is virtual area ,
here workspace don't know which one is existing and modified data)
--> Repository:- where stores data (commited file)
git config:-
=========
git config --global user.name "vinodh machi"
git config --global user.email "vinodhk070@gmail.com
git config --global push.default simple
git config --list
creating Repositorys:-
1. bare repo: is the centrailized repository which is used to store and share the
changes.
2. non-bare repo: user (or) workspace (or) local repository whih is used to modify
the changes.
mkdir central.git
git init --bare
git clone central.git <source> vinuspace <dest>
create file in workspace
move to staging area : git add java
move from staging repo : git commit -m "first chickin"
Git ignoring:
=============
--> .gitignore : is a conf file to ignore the unwanted runtime files like jar, war,
log....
1.class (Full name)
*.class (pattern matching)
Log viewing:
============
--> git log -3
--> git log --oneline --grep "workspace"
--> git log --grep "stringmasg" --oneline
--> git shortlog
--> git log --stat
git show --stat 23rt459bf
git show --name-status 23rt45bf
git show --name-only abc
Branching:-
===========
--> parallel development
--> storing of files in a repo is in the form of branches
ex: android windows
file1 file1
file2 file2
--> bare repo you will not have working dir, so i.e you not able to see
Merging:-
=========
--> Master(Target)<---------feature(source)
checkout command:-
==================
1. git checkout <BRANCH>:<COMMITID> --> specific commit('detached HEAD')
2. git checkout branch_name --> to switch one branch to another
3. git checkout -b <new-branch-name> --> creating and directly switching to new
branch
4. git checkout -- file1 file2 --> to dicard the changes in working directory(when
only files deleted,edited from work dir)
Removing files:
===============
rm
git rm filename
git clean -n(dry run means which are the file eligible to remove, very care full
before running this)
note: removes untracked files
git clean -f( removes the untracked file instead of adding to .gitignore conf file)
git rm :- will remove the file from the index and working directory ( only index if
you used --cached ) -
so that the deletion is staged for next commit.
When using git rm, the removal will part of your next commit. So if you want to
push the change you should use git rm
rm:-However, if you do end up using rm instead of git rm. You can skip the git add
and directly commit the changes using: git commit -a
Undo/Reverting Changes after adding to staging area :-
=====================================================
i added a file into staging area, now i want to modify it before going to commit
it?
Syntax: git reset HEAD <file>
sol is : 1. git reset (mixed is the default option)
2. git reset --mixed --> revert back / undo the changes from staging
area
3. git reset --hard --> to remove changes from all the 3 areas
@ working directory
@ staging Area
@ Repository(once file came to staging area, it
creats temperary commit id in repo)
4. git reset --soft --> remove changes only in repo temp id (HEAD)
HEAD--> once we add file into staging area it create one temp id in the repo as a
reference, this is the
latest commit id which we working.
HEAD:-
======
HEAD is the reference to the most recent commit in the current branch(In most of
the cases).
HEAD Doesn't point to most recent commit when we go into DETACHED HEAD State.
git show HEAD --> to see head commit
git difftool HEAD HEAD~1
Tags:-
-------
to identify/reference for a commitid to quick access/ creating specific point in
history for our repository
we cannot checkout tags in git but, we can create a branch from tag and checkout
the branch
git checkout -b <branch_name> <tag_name>(give already created tag names)
Diff:-
======
used to compare Changes,branches,and commits.
git diff --> diff b/n version in the working dir and version in the staging/index
area
git diff HEAD --> diff b/n version in working dir and commiting dir
git diff --cached --> diff b/n staging and commit versions
rebase --continue
rebase --abort
rebase --skip
workflow:-
=========
| Add | Commit |
|
|------------------------>|---------------------->|
|
|----------------Commit -a ---------------------->| git push
|
| |
|----------------------------->|
Working Dir Index Local Repository Remote Repository
(work space) (Staging) (HEAD)
|
| | |<----------git
fetch----------|
|<-------------------Merge------------------------|
|
| | | |
|<----------------------------------
Pull-----------------------------------------|
|<--------------------diff HEAD------------------>|
|
|<----------diff--------->|
Note:- the above commit -a option will only work for already known files to staging
area(i.e old files)
reflog:-
========
it shows when we commit,checkout branch, reset....etc
git reflog
git reflog --relative-date
git reflog show -all (or) <branch_name> for particular branch reflogs
git reflog show/HEAD@{5}
** Basically "git blame <file_name>" is used to show what revision and author last
modified each line of a file.
It's like checking the history of the development of a file.
Bisect:-
--------
first it will bisect/divide the given range into 2 parts and start executing
1. range between culprit/bug is there
2. pass Script file
git bisect file_name.rb
exit status 0(success) 1(failure)
Hooks:-
-------
hooks are programs which are auktomatically trigger at certail points in the git
execution cycle.
GitHub:- (ORS)
========
@ is a website to upload repositories online
@ Provides backup
@ Provides visual interface to repo
@ makes collaboration easier
git init
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/vinodhk070/hello.git
git push -u origin master