Monday, August 17, 2015

GIT

Configure GIT

git config --global user.name " Your Name"
git config --global user.email "name@email.com"

List Configurations
git config --global --list

Add Files to GIT

git add <ilename>
Adds all files including untracked ones.
git add -A
git status
git commit -m "comment"

Add (stage) the modified files

git add -u
(Only add updated files)

Look at the History

git log

View Changes

git diff dd6819..a15ec6

View Changes without SHA1 hash

git diff HEAD~1..HEAD
Below git assumes its HEAD
git diff HEAD~1..

Delete Files

rm <finename>
git add -u

Rename Files

mv <filename> <filename>
git add -A

Revert File Changes 

For Individual Files

git checkout <filename>

For Multiple Files

git reset --hard

Remove the Last commit and Move it to the staging area.

git reset --soft HEAD~1

(Moves the HEAD back and discard all the changes)
git reset --hard HEAD~1

Clean the Repository

Shows the files to be cleaned
git clean -n

Cleans the repository
git clean -f

GIT ignore File

.gitignore file content
/logs/*.txt
temp/
/deploy

View GIT Commit History

git log

Condense version

git log --oneline

Find no of commits in the repository

git log --oneline | wc -l

Shows different branches and merges that have happend

git log --oneline --graph

List the Authors and Commit messages of each of them

git shortlog

Summery / Ordered by Number of Commits with e-mail

git shortlog -sn

Details of the last commit

git show HEAD
Shows the commit before the last commit
git show HEAD~1

Use the SHA to display
git show 5642626

Remote Repositories

git remote

the output would be 'origin'. The 'origin' is the default name for where the source came from.

show the URI

git remote -v

Remove Remote URL

git remote rm upstream

Branches and Tags

Display the branches in the repository

git branch

Display the Remote branches in the repository

git branch -r

Tags

Stable points of the repository
git tag

Added Remote Repository to the Local Repository

git remote add origin <URI>

Fetching Changes for a Remote

git fetch

For multiple remotes

git fetch orgin

View Commit Log of the Remote Repository
git log origin/master

Merge The Changes

git merge origin/master

Branches

View Branch details
git log --graph --oneline --all --decorate

Added Alias
git config --global alias.lga "log --graph --oneline --all --decorate"

Create a new branch
git branch feature-1

Switch a Branch
git checkout feature-1

Create a branch with specific commit
git branch fix-1 974b56a

Rename & Delete Branches
git branch -m <branch name> <new name>
git branch -d <branch name>
Force Delete
git branch -D <branch name>

Find Where the HEAD has pointed
git reflog

Save Current Changes as STASH

git stash
git stash list
git stash apply

Merging

git merger fix-1



No comments:

Post a Comment