Git: Difference between revisions
No edit summary |
|||
| Line 297: | Line 297: | ||
==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 313: | ||
git pull origin master --rebase | git pull origin master --rebase | ||
|} | |||
==Git SSH Command== | ==Git SSH Command== | ||
| Line 335: | Line 341: | ||
==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 378: | ||
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 397: | ||
* [[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 409: | ||
* [[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 420: | ||
* [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= | |valign='top'| | ||
* [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 433: | ||
* [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 439: | ||
* [[Base64]] | * [[Base64]] | ||
| valign= | |valign='top'| | ||
|} | |} | ||
Revision as of 03: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
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 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 dtag |
git config --global --unset-all alias.dtag git dtag |
Git Stash
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
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 - sign before the value of --sort parameter
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
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 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
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
restore commit git reflog git reset --hard <sha value>
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
Let say there is a new feature needed to develop yourself. During the time of feature creation you have created git checkout -b your_private_branch 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.
|
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
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
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 git config pull.rebase false
git config pull.rebase true
git config pull.ff only
|
Global/Workstation/User Wise git config --global pull.rebase false
git config --global pull.rebase true
git config --global pull.ff only
|
Strategy merge (default) rebase (custom ) fast-forward only |
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 |