Git: Difference between revisions
No edit summary |
|||
| (8 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
{|class='wikitable' | |||
|valign='top'| | |||
git config --global user.name "Full Name" | git config --global user.name "Full Name" | ||
git config --global user.email "email.id@academia.chorke.org" | git config --global user.email "email.id@academia.chorke.org" | ||
| Line 16: | Line 18: | ||
'''list of assume unchanged files''' | '''list of assume unchanged files''' | ||
git ls-files -v|grep '^h' | git ls-files -v|grep '^h' | ||
|} | |||
==Git Ignore== | ==Git Ignore== | ||
{|class='wikitable' | |||
!scope='col' style='text-align:left' colspan='2'| | |||
Git Ignore | |||
|- | |||
|valign='top' style='width:50%'| | |||
out/ | out/ | ||
*.iml | *.iml | ||
| Line 33: | Line 41: | ||
'''clear metadata''' | '''clear metadata''' | ||
rm -rf */out */*.iml */*.ipr */*.iws */.idea */cmake-build-* */.idea_modules | rm -rf */out */*.iml */*.ipr */*.iws */.idea */cmake-build-* */.idea_modules | ||
|valign='top' style='width:50%'| | |||
|} | |||
==Git Alias== | ==Git Alias== | ||
{| | {|class='wikitable' | ||
| valign= | !scope='col' style='text-align:left' colspan='2'| | ||
Git Alias | |||
|- | |||
|valign='top' style='width:50%'| | |||
git config --global alias.lo "log --oneline" | git config --global alias.lo "log --oneline" | ||
git log --oneline | git log --oneline | ||
git lo | git lo | ||
| valign= | |valign='top' style='width:50%'| | ||
git config --global --unset-all alias.lo | git config --global --unset-all alias.lo | ||
git config --global --unset alias.lo | git config --global --unset alias.lo | ||
git lo | git lo | ||
|- | |- | ||
| valign= | |valign='top'| | ||
git config --global alias.lp 'log --pretty="%h %cD %cn %s"' | git config --global alias.lp 'log --pretty="%h %cD %cn %s"' | ||
git lp | git lp | ||
| valign= | |valign='top'| | ||
git config --global --unset-all alias.lp | git config --global --unset-all alias.lp | ||
git lp | git lp | ||
|- | |- | ||
| valign= | |valign='top'| | ||
git config --global alias.dtag "describe --tags $(git rev-list --tags --max-count=1)" | git config --global alias.dtag "describe \ | ||
--tags $(git rev-list --tags --max-count=1)" | |||
| valign= | |valign='top'| | ||
git config --global --unset-all alias.dtag | git config --global --unset-all alias.dtag | ||
git dtag | git dtag | ||
| Line 73: | Line 79: | ||
==Git Stash== | ==Git Stash== | ||
{| | {|class='wikitable' | ||
| valign= | !scope='col' style='text-align:left' colspan='2'| | ||
Git Stash | |||
|- | |||
|valign='top' style='width:50%'| | |||
git config --global alias.lo "log --o | |||
git stash apply stash@{index} | git stash apply stash@{index} | ||
git stash drop stash@{index} | git stash drop stash@{index} | ||
| Line 83: | Line 93: | ||
git stash | git stash | ||
| valign= | |valign='top' style='width:50%'| | ||
git apply --3way ~/.chorke/tmp/academia/patch/v1.0.00.patch | git apply --3way ~/.chorke/tmp/academia/patch/v1.0.00.patch | ||
git apply ~/.chorke/tmp/academia/patch/v1.0.00.patch | git apply ~/.chorke/tmp/academia/patch/v1.0.00.patch | ||
git diff > ~/.chorke/tmp/academia/patch/v1.0.00.patch | git diff > ~/.chorke/tmp/academia/patch/v1.0.00.patch | ||
git stash apply stash^{/stash_v1.0.00} | git stash apply stash^{/stash_v1.0.00} | ||
| Line 94: | Line 105: | ||
==Git Tag== | ==Git Tag== | ||
{|class='wikitable' | |||
!scope='col' style='text-align:left'| | |||
Git Tag | |||
|- | |||
|valign='top'| | |||
'''annotated tag''' | '''annotated tag''' | ||
git tag -a v1.5_initial_setup -m 'initial setup' | git tag -a v1.5_initial_setup -m 'initial setup' | ||
| Line 100: | Line 116: | ||
'''lightweight tag''' | '''lightweight tag''' | ||
git tag v1.5_initial_setup | git tag v1.5_initial_setup | ||
|- | |||
|valign='top'| | |||
''By default git sort order is ascending, for descending order we need to add <code>-</code> sign before the value of <code>--sort</code> parameter'' | ''By default git sort order is ascending, for descending order we need to add <code>-</code> sign before the value of <code>--sort</code> parameter'' | ||
|- | |||
|valign='top'| | |||
<syntaxhighlight lang="bash" highlight="8,9,12,13,21,22"> | <syntaxhighlight lang="bash" highlight="8,9,12,13,21,22"> | ||
git tag --sort=taggerdate | git tag --sort=taggerdate | ||
| Line 127: | Line 145: | ||
git log --tags --simplify-by-decoration --pretty='format:%ai %h %d' --date-order --graph | git log --tags --simplify-by-decoration --pretty='format:%ai %h %d' --date-order --graph | ||
</syntaxhighlight> | </syntaxhighlight> | ||
|} | |||
==Git Branch== | ==Git Branch== | ||
{|class='wikitable' | |||
!scope='col' style='text-align:left' colspan='2'| | |||
Git Branch | |||
|- | |||
|valign='top' style='width:50%'| | |||
'''create and checkout a new branch''' | '''create and checkout a new branch''' | ||
git checkout -b new_branch_name base_branch_name | git checkout -b new_branch_name base_branch_name | ||
| Line 146: | Line 170: | ||
git push origin -d old-dev-branch;\ | git push origin -d old-dev-branch;\ | ||
git push origin new-dev-branch | git push origin new-dev-branch | ||
|valign='top' style='width:50%'| | |||
|} | |||
==Git Rebase== | ==Git Rebase== | ||
{|class='wikitable' | |||
!scope='col' style='text-align:left' colspan='2'| | |||
Git Rebase | |||
|- | |||
|valign='top' style='width:50%'| | |||
git checkout '''<user-branch>''' | git checkout '''<user-branch>''' | ||
git pull --rebase origin '''<source-branch>''' | git pull --rebase origin '''<source-branch>''' | ||
| Line 165: | Line 197: | ||
'''merge :''' develop '''»''' uat '''»''' production '''»''' master | '''merge :''' develop '''»''' uat '''»''' production '''»''' master | ||
'''merge :''' staging '''»''' uat '''»''' production '''»''' master | '''merge :''' staging '''»''' uat '''»''' production '''»''' master | ||
|valign='top' style='width:50%'| | |||
|} | |||
==Git Commit== | ==Git Commit== | ||
{|class='wikitable' | |||
!scope='col' style='text-align:left' colspan='2'| | |||
Git Commit | |||
|- | |||
|valign='top' style='width:50%'| | |||
'''delete latest commit''' | '''delete latest commit''' | ||
git reset --hard HEAD~1 | git reset --hard HEAD~1 | ||
| Line 183: | Line 223: | ||
git cherry-pick <commit> | git cherry-pick <commit> | ||
|valign='top' style='width:50%'| | |||
|} | |||
==Git Reflog== | ==Git Reflog== | ||
{|class='wikitable' | |||
!scope='col' style='text-align:left' colspan='2'| | |||
Git Reflog | |||
|- | |||
|valign='top' style='width:50%'| | |||
'''restore commit''' | '''restore commit''' | ||
git reflog | git reflog | ||
git reset --hard <sha value> | git reset --hard <sha value> | ||
|valign='top' style='width:50%'| | |||
|} | |||
==Git Amend Commit== | ==Git Amend Commit== | ||
{|class='wikitable' | |||
!scope='col' style='text-align:left' colspan='2'| | |||
Git Amend Commit | |||
|- | |||
|valign='top' style='width:50%'| | |||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
git commit --amend | git commit --amend | ||
| Line 196: | Line 251: | ||
# git push origin <working-branch> --force | # git push origin <working-branch> --force | ||
</syntaxhighlight> | </syntaxhighlight> | ||
|valign='top' style='width:50%'| | |||
|} | |||
==Git Merge Commits== | ==Git Merge Commits== | ||
{|class='wikitable' | |||
!scope='col' style='text-align:left' colspan='2'| | |||
Git Merge Commits | |||
|- | |||
|valign='top' colspan='2'| | |||
Let say there is a new feature needed to develop yourself. During the time of feature creation you have created <code>git checkout -b your_private_branch</code> branch from any others branch like '''staging''' or '''develop'''. During the time of your development, let say you have added 50 commits for your own tracking. Now you needs to delete 49 commits and have to append your commit with the first commit. After that you need to update your central repository. | Let say there is a new feature needed to develop yourself. During the time of feature creation you have created <code>git checkout -b your_private_branch</code> branch from any others branch like '''staging''' or '''develop'''. During the time of your development, let say you have added 50 commits for your own tracking. Now you needs to delete 49 commits and have to append your commit with the first commit. After that you need to update your central repository. | ||
|- | |- | ||
|valign= | !scope='col' colspan='2'| Merge Commits Into Single | ||
|- | |||
|valign='top' style='width:50%'| | |||
'''Step: 1''' | '''Step: 1''' | ||
git checkout '''<your_private_branch>''' | git checkout '''<your_private_branch>''' | ||
| Line 216: | Line 276: | ||
git log | git log | ||
|valign= | |valign='top' style='width:50%'| | ||
'''Step: 3''' | '''Step: 3''' | ||
git commit --amend -m ''''<comment_about_feature>'''' | git commit --amend -m ''''<comment_about_feature>'''' | ||
| Line 228: | Line 288: | ||
|- | |- | ||
!scope='col' colspan='2'| Clean Dirty Branch & Start Again | |||
|- | |||
|valign='top' colspan='2'| | |||
For safety purpose you should check status and log to ensure your are not doing any wrong. Always be careful before <code> git push origin HEAD --force</code>. Before <code> git push origin HEAD --force</code> please keep backup of your branch into any other locations to avoid any kind of disaster & fast recovery <code>git pull origin your_private_branch</code>. | For safety purpose you should check status and log to ensure your are not doing any wrong. Always be careful before <code> git push origin HEAD --force</code>. Before <code> git push origin HEAD --force</code> please keep backup of your branch into any other locations to avoid any kind of disaster & fast recovery <code>git pull origin your_private_branch</code>. | ||
|- | |- | ||
|valign= | |valign='top'| | ||
git stash | git stash | ||
git stash clear | git stash clear | ||
git checkout '''<any_other_branch>''' | git checkout '''<any_other_branch>''' | ||
|valign= | |valign='top'| | ||
git branch -D '''<your_private_branch>''' | git branch -D '''<your_private_branch>''' | ||
git branch -d '''<your_private_branch>''' | git branch -d '''<your_private_branch>''' | ||
git checkout '''<your_private_branch>''' | git checkout '''<your_private_branch>''' | ||
|} | |} | ||
==Git Copy Changes== | ==Git Copy Changes== | ||
{|class='wikitable' | |||
!scope='col' style='text-align:left'| | |||
Git Copy Changes | |||
|- | |||
|valign='top'| | |||
'''diff changes:''' | '''diff changes:''' | ||
git diff > ~/Documents/ThinkPad_L14Gen3/my-diff-changes.txt | git diff > ~/Documents/ThinkPad_L14Gen3/my-diff-changes.txt | ||
| Line 267: | Line 331: | ||
scp legion:~/Documents/ThinkPad_L14Gen3/my-untracked-changes.txt ~/Documents/ThinkPad_L14Gen3/ | scp legion:~/Documents/ThinkPad_L14Gen3/my-untracked-changes.txt ~/Documents/ThinkPad_L14Gen3/ | ||
git apply ~/Documents/ThinkPad_L14Gen3/my-untracked-changes.txt | git apply ~/Documents/ThinkPad_L14Gen3/my-untracked-changes.txt | ||
|} | |||
==Git Warning== | ==Git Warning== | ||
{|class='wikitable' | |||
!scope='col' style='text-align:left' colspan='3'| | |||
Git Warning | |||
|- | |||
|valign='top' colspan='3'| | |||
''Pulling without specifying how to reconcile divergent branches is discouraged. You can squelch this message by running one of the following commands sometime before your next pull:'' | ''Pulling without specifying how to reconcile divergent branches is discouraged. You can squelch this message by running one of the following commands sometime before your next pull:'' | ||
|- | |||
| | !scope='col' style='width:33%'| Local/Project Wise | ||
''' | !scope='col' style='width:34%'| Global/Workstation/User Wise | ||
!scope='col' style='width:33%'| Strategy | |||
|- | |||
|valign='top'| | |||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
git config pull.rebase false | git config pull.rebase false | ||
| Line 278: | Line 351: | ||
git config pull.ff only | git config pull.ff only | ||
</syntaxhighlight> | </syntaxhighlight> | ||
| | |||
|valign='top'| | |||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
git config --global pull.rebase false | git config --global pull.rebase false | ||
| Line 285: | Line 358: | ||
git config --global pull.ff only | git config --global pull.ff only | ||
</syntaxhighlight> | </syntaxhighlight> | ||
| | |||
|valign='top'| | |||
merge (default) | merge (default) | ||
rebase (custom ) | rebase (custom ) | ||
fast-forward only | fast-forward only | ||
|} | |||
==Git Archive Branch== | |||
{|class='wikitable' | |||
!scope='col' style='text-align:left' colspan='2'| | |||
Git Archive Reference | |||
|- | |||
|valign='top' style='width:50%'| | |||
<syntaxhighlight lang="bash"> | |||
git branch | |||
# feature-branch-01 | |||
# feature-branch-02 | |||
</syntaxhighlight> | |||
|valign='top' style='width:50%'| | |||
<syntaxhighlight lang="bash"> | |||
git for-each-ref refs/heads | |||
git for-each-ref refs/remotes | |||
git for-each-ref refs/archive | |||
</syntaxhighlight> | |||
|- | |||
|valign='top'| | |||
<syntaxhighlight lang="bash"> | |||
# create an archive reference | |||
git update-ref refs/archive/feature-branch-01 \ | |||
feature-branch-01 | |||
</syntaxhighlight> | |||
|valign='top'| | |||
<syntaxhighlight lang="bash"> | |||
# create an archive reference | |||
git update-ref refs/archive/feature-branch-02 \ | |||
feature-branch-02 | |||
</syntaxhighlight> | |||
|- | |||
|valign='top'| | |||
<syntaxhighlight lang="bash"> | |||
# delete branch from heads | |||
git branch -D feature-branch-01 | |||
</syntaxhighlight> | |||
|valign='top'| | |||
<syntaxhighlight lang="bash"> | |||
# delete branch from heads | |||
git branch -D feature-branch-02 | |||
</syntaxhighlight> | |||
|- | |||
|valign='top' colspan='2'| | |||
<syntaxhighlight lang="bash"> | |||
git for-each-ref refs/archive | |||
# fbcbeddd9f8fd88ca4be2be97be9da9eaed0bff5 commit refs/archive/feature-branch-01 | |||
# 943bf8396c17ed135e8f4e8ada5d7ce744f8e98f commit refs/archive/feature-branch-02 | |||
</syntaxhighlight> | |||
|- | |||
|valign='top'| | |||
<syntaxhighlight lang="bash"> | |||
# restore an archive reference | |||
git checkout -b feature-branch-01 \ | |||
refs/archive/feature-branch-01 | |||
</syntaxhighlight> | |||
|valign='top'| | |||
<syntaxhighlight lang="bash"> | |||
# restore an archive reference | |||
git checkout -b feature-branch-02 \ | |||
refs/archive/feature-branch-02 | |||
</syntaxhighlight> | |||
|- | |||
|valign='top'| | |||
<syntaxhighlight lang="bash"> | |||
# delete an archive reference | |||
git update-ref -d refs/archive/feature-branch-01 | |||
</syntaxhighlight> | |||
|valign='top'| | |||
<syntaxhighlight lang="bash"> | |||
# delete an archive reference | |||
git update-ref -d refs/archive/feature-branch-02 | |||
</syntaxhighlight> | |||
|} | |} | ||
==Rename a Git Remote== | ==Rename a Git Remote== | ||
{|class='wikitable' | |||
!scope='col' style='text-align:left' colspan='2'| | |||
Rename a Git Remote | |||
|- | |||
|valign='top' style='width:50%'| | |||
git remote rename <old-name> <new-name> | git remote rename <old-name> <new-name> | ||
git remote rename '''origin''' '''gitea_origin''' | git remote rename '''origin''' '''gitea_origin''' | ||
|valign='top' style='width:50%'| | |||
|} | |||
==Git Https Remote Auth== | ==Git Https Remote Auth== | ||
{|class='wikitable mw-collapsible' | |||
!scope='col' style='text-align:left'| | |||
Git Https Remote Auth | |||
|- | |||
|valign='top'| | |||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
CODECOMMIT_USERNAME='<username>';\ | CODECOMMIT_USERNAME='<username>';\ | ||
| Line 308: | Line 472: | ||
git pull origin master --rebase | git pull origin master --rebase | ||
|} | |||
==Git SSH Command== | ==Git SSH Command== | ||
| Line 335: | Line 500: | ||
==Knowledge== | ==Knowledge== | ||
{|class='wikitable mw-collapsible' | |||
!scope='col' style='text-align:left'| | |||
Knowledge | |||
|- | |||
|valign='top'| | |||
'''discard changes''' | '''discard changes''' | ||
git checkout master -f | git checkout master -f | ||
| Line 367: | Line 537: | ||
git checkout uat | git checkout uat | ||
git pull --rebase origin staging | git pull --rebase origin staging | ||
|} | |||
==References== | ==References== | ||
{| | {|class='wikitable mw-collapsible' | ||
| valign= | !scope='col' style='text-align:left' colspan='3'| | ||
References | |||
|- | |||
|valign='top' style='width:33%'| | |||
* [[Execute bash script from URL]] | * [[Execute bash script from URL]] | ||
* [[Bash/SQLPlus/Input/Redirect|Bash/SQLPlus Input Redirect]] | * [[Bash/SQLPlus/Input/Redirect|Bash/SQLPlus Input Redirect]] | ||
| Line 382: | Line 556: | ||
* [[Bash/Port]] | * [[Bash/Port]] | ||
| valign= | |valign='top' style='width:34%'| | ||
* [[Develop GitHub Pages Site Locally by Jekyll]] | * [[Develop GitHub Pages Site Locally by Jekyll]] | ||
* [https://stackoverflow.com/questions/21676150/ Setup Git Bash in Intellij Terminal] | * [https://stackoverflow.com/questions/21676150/ Setup Git Bash in Intellij Terminal] | ||
| Line 394: | Line 568: | ||
* [[GitLab]] | * [[GitLab]] | ||
| valign= | |valign='top' style='width:33%'| | ||
* [https://www.digitalocean.com/community/tutorials/how-to-use-git-hooks-to-automate-development-and-deployment-tasks Git Hooks To Automate Development and Deployment] | * [https://www.digitalocean.com/community/tutorials/how-to-use-git-hooks-to-automate-development-and-deployment-tasks Git Hooks To Automate Development and Deployment] | ||
* [https://stackoverflow.com/questions/28166547/ Differences of <code>revert</code>, <code>amend</code>, <code>rollback</code> & <code>undo</code>] | * [https://stackoverflow.com/questions/28166547/ Differences of <code>revert</code>, <code>amend</code>, <code>rollback</code> & <code>undo</code>] | ||
| Line 405: | Line 579: | ||
* [https://stackoverflow.com/questions/6900328/ Git show all (lightweight) Tags] | * [https://stackoverflow.com/questions/6900328/ Git show all (lightweight) Tags] | ||
* [https://git-scm.com/book/en/v2/Distributed-Git-Maintaining-a-Project Git Maintaining a Project] | * [https://git-scm.com/book/en/v2/Distributed-Git-Maintaining-a-Project Git Maintaining a Project] | ||
|- | |- | ||
|valign='top'| | |||
| valign= | |||
* [https://stackoverflow.com/questions/6372044/ Git merge a commit into another branch] | * [https://stackoverflow.com/questions/6372044/ Git merge a commit into another branch] | ||
* [https://stackoverflow.com/questions/17577409/ Git remove merge commit from history] | * [https://stackoverflow.com/questions/17577409/ Git remove merge commit from history] | ||
| Line 422: | Line 592: | ||
* [https://www.atlassian.com/git/tutorials/gitk Gitk] | * [https://www.atlassian.com/git/tutorials/gitk Gitk] | ||
| valign= | |valign='top'| | ||
* [https://stackoverflow.com/questions/1139762/ Ignore files that have already been committed] | * [https://stackoverflow.com/questions/1139762/ Ignore files that have already been committed] | ||
* [https://docs.github.com/en/pull-requests/committing-changes-to-your-project/creating-and-editing-commits/changing-a-commit-message Git » Changing a commit message] | * [https://docs.github.com/en/pull-requests/committing-changes-to-your-project/creating-and-editing-commits/changing-a-commit-message Git » Changing a commit message] | ||
| Line 428: | Line 598: | ||
* [[Base64]] | * [[Base64]] | ||
| valign= | |valign='top'| | ||
|} | |} | ||
Latest revision as of 04:51, 20 February 2026
git config --global user.name "Full Name" git config --global user.email "email.id@academia.chorke.org" git config --global pull.rebase true git config --global core.autocrlf input git config --global init.defaultBranch develop git config advice.skippedCherryPicks false undo or remove from index git rm --cache src/test/resources/application.properties undo or redo assume unchanged git update-index --no-assume-unchanged src/main/resources/application.properties git update-index --assume-unchanged src/main/resources/application.properties list of assume unchanged files git ls-files -v|grep '^h' |
Git Ignore
|
Git Ignore | |
|---|---|
out/ *.iml *.ipr *.iws .idea/* cmake-build-*/ .idea_modules/ fabric.properties crashlytics.properties atlassian-ide-plugin.xml crashlytics-build.properties com_crashlytics_export_strings.xml clear metadata rm -rf */out */*.iml */*.ipr */*.iws */.idea */cmake-build-* */.idea_modules |
|
Git Alias
|
Git Alias | |
|---|---|
git config --global alias.lo "log --oneline" git log --oneline git lo |
git config --global --unset-all alias.lo git config --global --unset alias.lo git lo |
git config --global alias.lp 'log --pretty="%h %cD %cn %s"' git lp |
git config --global --unset-all alias.lp git lp |
git config --global alias.dtag "describe \ --tags $(git rev-list --tags --max-count=1)" |
git config --global --unset-all alias.dtag git dtag |
Git Stash
|
Git Stash | |
|---|---|
git config --global alias.lo "log --o
git stash apply stash@{index}
git stash drop stash@{index}
git stash pop stash@{index}
git stash clear
git stash list
git stash
|
git apply --3way ~/.chorke/tmp/academia/patch/v1.0.00.patch
git apply ~/.chorke/tmp/academia/patch/v1.0.00.patch
git diff > ~/.chorke/tmp/academia/patch/v1.0.00.patch
git stash apply stash^{/stash_v1.0.00}
git stash push -m stash_v1.0.00
git stash drop
|
Git Tag
|
Git Tag |
|---|
annotated tag git tag -a v1.5_initial_setup -m 'initial setup' git tag -a v1.5_initial_setup lightweight tag git tag v1.5_initial_setup |
|
By default git sort order is ascending, for descending order we need to add |
git tag --sort=taggerdate
git tag -l --sort=taggerdate
git tag -l --format='%(taggerdate) %(refname)'
git tag -l --format='%(taggerdate) %(refname)' --sort=taggerdate
# ascending order
git tag -l --format='%(taggerdate)%09%(refname)' --sort=taggerdate
git tag -l --format='%(creatordate)%09%(refname)' --sort=creatordate
# descending order
git tag -l --format='%(taggerdate)%09%(refname)' --sort=-taggerdate
git tag -l --format='%(creatordate)%09%(refname)' --sort=-creatordate
git tag --format='%(creatordate:short)%09%(refname:strip=2)'
git tag --format='%(creatordate:short)%09%(refname:strip=2)' --sort=creatordate
git tag --format='%(taggerdate:short)%09%(refname:strip=2)'
git tag --format='%(taggerdate:short)%09%(refname:strip=2)' --sort=taggerdate
git log --tags --simplify-by-decoration --pretty='format:%ai %d'
git log --tags --simplify-by-decoration --pretty='format:%ai %h %d' --date-order --graph
|
Git Branch
|
Git Branch | |
|---|---|
create and checkout a new branch git checkout -b new_branch_name base_branch_name git checkout -b new_branch_name renaming and delete branch git branch -m old_branch_name new_branch_name git branch -D branch_to_delete_without_merge_status git branch -d branch_to_delete git push -d origin branch_to_delete git push origin --delete branch_to_delete renaming branch name git checkout develop;\ git checkout -b new-dev-branch old-dev-branch;\ git push origin -d old-dev-branch;\ git push origin new-dev-branch |
|
Git Rebase
|
Git Rebase | |
|---|---|
git checkout <user-branch> git pull --rebase origin <source-branch> user branches merge into official branch ───────────────────────────────────────── merge : user-branch » develop|master merge : user-branch » staging|uat|production official branches rebase into user branch ────────────────────────────────────────── rebase: user-branch « develop|master rebase: user-branch « staging|uat|production official branches merge into official branch ───────────────────────────────────────────── merge : develop » uat » production » master merge : staging » uat » production » master |
|
Git Commit
|
Git Commit | |
|---|---|
delete latest commit git reset --hard HEAD~1 rollback to the commit id git reset --hard <sha1-commit-id> delete commit from remote branch git push origin HEAD --force delete commit from local branch git checkout <your-branch> git fetch --all && git reset --hard origin/<your-branch> merge commit from another branch git cherry-pick <commit> |
|
Git Reflog
|
Git Reflog | |
|---|---|
restore commit git reflog git reset --hard <sha value> |
|
Git Amend Commit
|
Git Amend Commit | |
|---|---|
git commit --amend
git commit --amend -C HEAD
git push origin HEAD --force
# git push origin <working-branch> --force
|
|
Git Merge Commits
|
Git Merge Commits | |
|---|---|
|
Let say there is a new feature needed to develop yourself. During the time of feature creation you have created | |
| Merge Commits Into Single | |
Step: 1 git checkout <your_private_branch> git status git log Step: 2 git reset --soft <hash_of_first_commit> git status git log |
Step: 3 git commit --amend -m '<comment_about_feature>' git status git log Step: 4 (final) git push origin HEAD --force git status git log |
| Clean Dirty Branch & Start Again | |
|
For safety purpose you should check status and log to ensure your are not doing any wrong. Always be careful before | |
git stash git stash clear git checkout <any_other_branch> |
git branch -D <your_private_branch> git branch -d <your_private_branch> git checkout <your_private_branch> |
Git Copy Changes
|
Git Copy Changes |
|---|
diff changes: git diff > ~/Documents/ThinkPad_L14Gen3/my-diff-changes.txt scp legion:~/Documents/ThinkPad_L14Gen3/my-diff-changes.txt ~/Documents/ThinkPad_L14Gen3/ git apply ~/Documents/ThinkPad_L14Gen3/my-diff-changes.txt tracked changes only: git stash save my-tracked-changes git stash show -p > ~/Documents/ThinkPad_L14Gen3/my-tracked-changes.txt git stash pop scp legion:~/Documents/ThinkPad_L14Gen3/my-tracked-changes.txt ~/Documents/ThinkPad_L14Gen3/ git apply ~/Documents/ThinkPad_L14Gen3/my-tracked-changes.txt include untracked changes: git stash save --include-untracked my-untracked-changes git stash show -p > ~/Documents/ThinkPad_L14Gen3/my-untracked-changes.txt git stash pop scp legion:~/Documents/ThinkPad_L14Gen3/my-untracked-changes.txt ~/Documents/ThinkPad_L14Gen3/ git apply ~/Documents/ThinkPad_L14Gen3/my-untracked-changes.txt |
Git Warning
|
Git Warning | ||
|---|---|---|
|
Pulling without specifying how to reconcile divergent branches is discouraged. You can squelch this message by running one of the following commands sometime before your next pull: | ||
| Local/Project Wise | Global/Workstation/User Wise | Strategy |
git config pull.rebase false
git config pull.rebase true
git config pull.ff only
|
git config --global pull.rebase false
git config --global pull.rebase true
git config --global pull.ff only
|
merge (default) rebase (custom ) fast-forward only |
Git Archive Branch
|
Git Archive Reference | |
|---|---|
git branch
# feature-branch-01
# feature-branch-02
|
git for-each-ref refs/heads
git for-each-ref refs/remotes
git for-each-ref refs/archive
|
# create an archive reference
git update-ref refs/archive/feature-branch-01 \
feature-branch-01
|
# create an archive reference
git update-ref refs/archive/feature-branch-02 \
feature-branch-02
|
# delete branch from heads
git branch -D feature-branch-01
|
# delete branch from heads
git branch -D feature-branch-02
|
git for-each-ref refs/archive
# fbcbeddd9f8fd88ca4be2be97be9da9eaed0bff5 commit refs/archive/feature-branch-01
# 943bf8396c17ed135e8f4e8ada5d7ce744f8e98f commit refs/archive/feature-branch-02
| |
# restore an archive reference
git checkout -b feature-branch-01 \
refs/archive/feature-branch-01
|
# restore an archive reference
git checkout -b feature-branch-02 \
refs/archive/feature-branch-02
|
# delete an archive reference
git update-ref -d refs/archive/feature-branch-01
|
# delete an archive reference
git update-ref -d refs/archive/feature-branch-02
|
Rename a Git Remote
|
Rename a Git Remote | |
|---|---|
git remote rename <old-name> <new-name> git remote rename origin gitea_origin |
|
Git Https Remote Auth
|
Git Https Remote Auth |
|---|
CODECOMMIT_USERNAME='<username>';\
CODECOMMIT_PASSWORD='<password>';\
tee ${HOME}/.netrc >/dev/null <<EOF
machine git-codecommit.ap-southeast-1.amazonaws.com
login ${CODECOMMIT_USERNAME}
password ${CODECOMMIT_PASSWORD}
EOF
git pull origin master --rebase |
Git SSH Command
GIT_SSH_COMMAND="ssh\
-o StrictHostKeyChecking=no\
-o UserKnownHostsFile=/dev/null"\
git clone --depth=1 --single-branch\
--branch master git@scm.chorke.org:chorke/academia\
/config.git $HOME/.config/chorke/academia/config_master 2>/dev/null\
|| git -C $HOME/.config/chorke/academia/config_master pull
|
export GIT_SSH_COMMAND="ssh\
-o StrictHostKeyChecking=no\
-o UserKnownHostsFile=/dev/null";\
export GIT_CLONE_TARGET="${HOME}/.config/chorke/academia/config_master";\
export GIT_CLONE_SOURCE='git@scm.chorke.org:chorke/academia/config.git';\
git clone --depth=1 --single-branch --branch master $GIT_CLONE_SOURCE\
$GIT_CLONE_TARGET 2>/dev/null || git -C $GIT_CLONE_TARGET pull
|
Knowledge
|
Knowledge |
|---|
discard changes git checkout master -f delete and recreate git branch -d staging git branch -D staging debug ssh connection ssh -v git@bitbucket.org ssh -T git@bitbucket.org ssh -vT git@bitbucket.org git merge develop git fetch origin staging git checkout -b staging origin/staging git config --global init.defaultBranch master git stashing git stash; git checkout -b new_branch; git stash pop git add .; git commit -m "new feature added"; git push git remote -v;mv src/main/resources/application.properties ..;cd .. mv ../application.properties src/main/resources/ rebase vs merge git rebase master #all the updated commits of master will be available in the feature branch git merge --squash feature #all the feature commits replaced by a new commit in the master git commit -m 'feature merged with master branch' git checkout uat git pull --rebase origin staging |