Created
September 28, 2018 13:37
-
-
Save rajacsp/57abfd710094264fb2339002a2b7fa00 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Basic flow: (basis status check, add, commit, push) | |
git status | |
git add . | |
git commit -m "dc-00: comment" | |
git push | |
git diff *_client.html | |
git checkout -- abc.java | |
git commit filename | |
git diff --cached [filename] | |
git diff HEAD [filename] | |
Configure user details on Git | |
git config --global user.email "[email protected]" | |
git config --global user.name "Your Name" | |
git cache / github password cache: | |
git config credential.helper store | |
reset a single file: | |
git checkout filename | |
http://www.norbauer.com/rails-consulting/notes/git-revert-reset-a-single-file.html | |
git commit some files: | |
http://stackoverflow.com/questions/7239333/how-do-i-commit-only-some-files | |
end git diff: | |
type q | |
revert last push: | |
git reset --hard <revision_id_of_last_known_good_commit> | |
git push --force | |
more: | |
http://stackoverflow.com/questions/6655052/is-there-a-way-to-rollback-my-last-push-to-git | |
Git Tutorial: | |
https://www.atlassian.com/git/tutorials/syncing/git-fetch | |
git cheat sheet: | |
https://training.github.com/kit/downloads/github-git-cheat-sheet.pdf | |
git commands: | |
https://www.siteground.com/tutorials/git/commands.htm | |
https://www.atlassian.com/git/tutorials/setting-up-a-repository | |
more: | |
https://www.atlassian.com/git/tutorials/saving-changes | |
------------------------------ | |
# | |
add all except a single file | |
git add . | |
git reset filename | |
# Git logs: | |
git log | |
# Git logs with limit | |
git log -n 2 | |
# Git previous logs one line | |
git log --pretty=oneline | |
# Git stats | |
git log --stat | |
git log --stat -n 2 | |
# Git log for particular author | |
git log --author="rajacsp" -n 2 | |
# Git log graph: | |
git log --graph --decorate --oneline | |
ref: | |
https://git-scm.com/book/en/v2/Git-Basics-Viewing-the-Commit-History | |
https://www.atlassian.com/git/tutorials/inspecting-a-repository | |
https://git-scm.com/docs/git-status | |
------------------------------ | |
# | |
Revert all uncommitted changes including new files: | |
# Revert changes to modified files. | |
git reset --hard | |
------------------------------ | |
# Remove all untracked files and directories. (`-f` is `force`, `-d` is `remove directories`) | |
git clean -fd | |
------------------------------ | |
# | |
Undo a last add before commit | |
git reset | |
------------------------------ | |
# | |
Revert a single file: | |
git checkout filename | |
http://www.norbauer.com/rails-consulting/notes/git-revert-reset-a-single-file.html | |
------------------------------ | |
# | |
Git add all but ignore one file: | |
git add -u | |
git reset -- filename.txt | |
------------------------------ | |
# | |
revert one uncommitted file git | |
git checkout abc.php | |
source: http://www.norbauer.com/rails-consulting/notes/git-revert-reset-a-single-file.html | |
------------------------------ | |
# | |
clone | |
git clone https://github.com/rajacsp/drivercheck | |
------------------------------ | |
# | |
ignore class files git | |
/*.class in gitignore | |
http://stackoverflow.com/questions/4308610/how-to-ignore-certain-files-in-git | |
------------------------------ | |
# | |
echo "# drivercheck" >> README.md | |
git init | |
git add README.md | |
git commit -m "first commit" | |
git remote add origin https://github.com/rajacsp/drivercheck.git | |
git push -u origin master | |
warning: LF will be replaced by CRLF in | |
------------------------------ | |
# | |
Short log: | |
git shortlog -s | |
will get all users' commit by count | |
------------------------------ | |
# Total commits count in Head, Branch and All | |
git rev-list --count HEAD | |
- will get the total commits in head | |
git rev-list --all --count | |
- will get the total commits in all | |
git rev-list --count origin/K-develop | |
https://stackoverflow.com/questions/677436/how-do-i-get-the-git-commit-count | |
------------------------------ | |
#follow this to avoid username/password asking option | |
# reach the right folder | |
cd /var/lib/jenkins/workspace/foj_rest | |
git config credential.helper store | |
git pull https://bitbucket.org/teamtode/foj_rest.git | |
git config credential.helper store | |
git pull https://bitbucket.org/teamtode/tode_rest_php.git | |
Caching your GitHub password in Git: | |
https://help.github.com/articles/caching-your-github-password-in-git/ | |
------------------------------ | |
# | |
Take branch | |
git checkout -b branch_name | |
https://github.com/Kunena/Kunena-Forum/wiki/Create-a-new-branch-with-git-and-manage-branches | |
git clone abc.git branch abc_branch | |
------------------------------ | |
# Merge branch with Master (puhsing branch's code into master): verified on Feb 10, 2017 | |
go inside master folder: | |
git pull origin master | |
git merge branch_name | |
git push origin master | |
------------------------------ | |
# if conflict occurs, fix them using method below: | |
<<<<<<< HEAD - old code start | |
======= - old code end | |
>>>>>>> plainreport - new code end | |
How to fix Git merge conflicts: | |
https://www.youtube.com/watch?v=g8BRcB9NLp4 | |
OR | |
git checkout master | |
git pull origin master | |
git merge branch_name | |
git push origin master | |
more: http://stackoverflow.com/questions/5601931/best-and-safest-way-to-merge-a-git-branch-into-master | |
OR | |
git pull origin K-develop | |
git merge origin/K-develop | |
git push | |
------------------------------ | |
# | |
Find Git Version in cmd: | |
git --version | |
git version 2.16.2.windows.1 | |
if you get "command not found", it simply means that you haven't installed | |
http://superuser.com/questions/347728/terminal-command-to-find-what-version-of-git-i-have-installed | |
------------------------------ | |
# | |
Pull Request: | |
https://help.github.com/articles/about-pull-requests/ | |
------------------------------ | |
# | |
Git Cherry pick | |
git cherry-pick <commit-id> | |
https://mirrors.edge.kernel.org/pub/software/scm/git/docs/git-cherry-pick.html | |
https://stackoverflow.com/questions/881092/how-to-merge-a-specific-commit-in-git | |
https://stackoverflow.com/questions/880957/pull-all-commits-from-a-branch-push-specified-commits-to-another/881014#881014 | |
http://markosullivan.ca/how-to-handle-a-pull-request-from-github/ | |
------------------------------ | |
# | |
Rewrite old history in GIT: | |
java -jar c:/bfg/bfg-1.13.0.jar --delete-file *.mp3 pythonsamples.git | |
java -jar c:/bfg/bfg-1.13.0.jar --strip-blobs-bigger-than 30M pythonsamples.git | |
cd pythonsamples.git | |
git reflog expire --expire=now --all && git gc --prune=now --aggressive | |
https://rtyley.github.io/bfg-repo-cleaner/#usage | |
------------------------------ | |
# | |
Rename previous commit: | |
git commit --amend -m "TACT-436: Script alignment made" | |
------------------------------ | |
# | |
change commit message after git push | |
git commit --amend -m "Message" | |
git push --force-with-lease | |
ref: | |
https://stackoverflow.com/questions/8981194/changing-git-commit-message-after-push-given-that-no-one-pulled-from-remote | |
or | |
git rebase -i eb5661a8e4de761d2af79c5ecbdbc875c34481fa | |
https://superuser.com/questions/751699/is-there-a-way-to-edit-a-commit-message-in-github/751909 | |
------------------------------ | |
# | |
Stash existing changes: | |
git stash (will stash your existing changes) | |
git pull (pull all of your new changes from central repository) | |
git stash apply (bring back your old changes on top of new code) | |
ref: | |
https://git-scm.com/book/en/v1/Git-Tools-Stashing | |
------------------------------ | |
# | |
View stash files: | |
git stash show | |
ref: | |
https://stackoverflow.com/questions/3573623/is-it-possible-to-preview-stash-contents-in-git | |
https://stackoverflow.com/questions/11693074/git-credential-cache-is-not-a-git-command | |
------------------------------ | |
# | |
Delete a branch | |
git push -d <remote_name> <branch_name> | |
git branch -d <branch_name> | |
delete multiple branches: | |
git push -d <remote_name> <branch_name_1> <branch_name_2> | |
ref: | |
https://stackoverflow.com/questions/2003505/how-do-i-delete-a-git-branch-both-locally-and-remotely | |
https://stackoverflow.com/questions/3670355/can-you-delete-multiple-branches-in-one-command-with-git | |
------------------------------ | |
# | |
Copy Repository with history: | |
https://developer.atlassian.com/blog/2016/01/totw-copying-a-full-git-repo/ | |
------------------------------ | |
# | |
git status -uno | |
-------------------------------------------------/Git Commands---------------------------- | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment