Git - Frequently Used
Some git commands I frequently use but sometimes keep forgetting.
restore
# restore a filegit restore --source <branch_name> <file_relative_path># restore to mastergit restore --source master pages/docs/index.tsx# restore to one last commit in mastergit restore --source master~1 pages/docs/index.tsx# restore to one last commit in current branchgit restore -source=HEAD~1 pages/docs/index.tsx# restore a foldergit restore --source <branch_name> <folder_relative_path>git restore -source=HEAD~1 pages/docs
references : git-tower
rebase
# init rebasegit rebase <upstream> <branch_name># pull and rebasegit pull --rebase <upstream> <branch_name># when resolve conflicts## after resolving conflicts and add to stagedgit rebase --continue## to cancel rebase processgit rebase --abort
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_agit reset HEAD~1git checkout -b branch_b# orgit checkout branch_bgit add --allgit commit -m "commit message"
remove created tag
git tag -d <tag_name>