Configure GIT
git config --global user.name " Your Name"
git config --global user.email "name@email.com"
List Configurations
git config --global --list
Adds all files including untracked ones.
git add -A
Add Files to GIT
git add <ilename>Adds all files including untracked ones.
git add -A
git status
git commit -m "comment"
(Only add updated files)
Below git assumes its HEAD
git diff HEAD~1..
git add -u
git add -A
(Moves the HEAD back and discard all the changes)
git reset --hard HEAD~1
git clean -n
Cleans the repository
git clean -f
git commit -m "comment"
Add (stage) the modified files
git add -u(Only add updated files)
Look at the History
git logView Changes
git diff dd6819..a15ec6View Changes without SHA1 hash
git diff HEAD~1..HEADBelow 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 --hardRemove 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 cleanedgit clean -n
Cleans the repository
git clean -f
GIT ignore File
.gitignore file content/logs/*.txt
temp/
/deploy
View GIT Commit History
git logCondense version
git log --onelineFind no of commits in the repository
git log --oneline | wc -lShows different branches and merges that have happend
git log --oneline --graphList the Authors and Commit messages of each of them
git shortlogSummery / Ordered by Number of Commits with e-mail
git shortlog -snDetails of the last commit
git show HEADShows 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 -vRemove Remote URL
git remote rm upstreamBranches and Tags
Display the branches in the repository
git branchDisplay 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