frequently used commands¶
some git commands i frequently use but sometimes keep forgetting.
restore¶
restore a file
restore to main
branch
restore to the last commit in main
restore to last commit in current branch
restore a folder
references : git-tower
rebase¶
init rebase
pull and rebase
after resolving conflicts and add to stage
to cancel rebase process
references : git docs
relocate last commit to another branch¶
when you accidentally commit to branch_a
but actually you want to commit it in branch_b
git checkout branch_a
git reset HEAD~1
git checkout -b branch_b
# or
git checkout branch_b
git add --all
git commit -m "commit message"
remove created tag¶
rename a tag¶
create an tag alias with a new name
remove the old tag locally
remove the tag on the remote, with a checkout
the third argument is your remote repo. in our example, origin
finally, add the new tag to the remote repo. the new tag will not be added until this is done.
repeat this process in all remotes.
reference: stackoverflow
use ssh key to sign a commit¶
this only works with git 2.34.0 or newer and openssh 8.0 or newer.
configure git to use ssh for commit signing, and tell git which key must be used
use the -S
flag when signing your commits:
or tell git to sign your commits automatically
use gpg to sign a commit¶
list all your keys
we need this hexadecimal value after the slash. add this value to your git config.
replace 7DD21DBA
by your hexadecimal value from the last command. to use this key in only one repo, run the last command without the --global
. when you do an commit, add the -s
option.
to confirm:
getting the difference between two repositories¶
# go to repo_a
cd /home/user/repo_a
# add the repo_b as a remote
git remote add -f b /home/user/repo_b
# see the differences on branch main
git diff main remotes/b/main
# when you're done, remove the remote
git remote rm b
reference: git: getting the difference between two repositories