常用git命令

分支

名称备注
git branchList all local branches.
git branch -aList remote and local branches.
git checkout -b branch_nameCreate a local branch and switch to it.
git checkout branch_nameSwitch to an existing branch.
git push origin branch_namePush branch to remote.
git branch -m new_nameRename current branch.
git branch -d branch_nameDelete a local branch.
git push origin :branch_nameDelete a remote branch.

日志

名称备注
git log --onelineShow commit history in single lines.
git log -2Show commit history for last N commits.
git log -p -2Show commit history for last N commits with diff.
git diffShow all local file changes in the working tree.
git diff myfileShow changes made to a file.
git blame myfileShow who changed what & when in a file.
git remote show originShow remote branches and their mapping to local.

清理

名称备注
git clean -fDelete all untracked files.
git clean -dfDelete all untracked files and directories.
git checkout -- .Undo local modifications to all files.
git reset HEAD myfileUnstage a file.

标签

名称备注
git pull --tagsGet remote tags.
git checkout tag_nameSwitch to an existing tag.
git tagList all tags.
git tag -a tag_name -m "tag message"Create a new tag.
git push --tagsPush all tags to remote repo.
STASHES.备注
git stash save "stash name" && git stashSave changes to a stash.
git stash listList all stashes.
git stash popApply a stash and delete it from stash list.

作者:spike

分类: Tool

创作时间:2023-08-31

更新时间:2024-12-09

联系方式放在中括号之中例如[[email protected]],回复评论在开头加上标号例如:#1