git常用命令

2021-05-28  本文已影响0人  流水潺湲

一、新建代码库

$ git init

$ git init [project-name]

$ git clone [url]

二、配置

Git的设置文件为.gitconfig,它可以在用户主目录下(全局配置),也可以在项目目录下(项目配置)。

$ git config --list

$ git config -e [--global]

$ git config [--global] user.name "[name]"

$ git config [--global] user.email "[email address]"

三、增加/删除文件

$ git add [file1] [file2] ...

$ git add [dir]

$ git add .

$ git add -p

$ git rm [file1] [file2] ...

$ git rm --cached [file]

$ git mv [file-original] [file-renamed]

四、代码提交

$ git commit -m [message]

$ git commit [file1] [file2] ... -m [message]

$ git commit -a

$ git commit -v

如果代码没有任何新变化,则用来改写上一次commit的提交信息

$ git commit --amend -m [message]

$ git commit --amend [file1] [file2] ...

五、分支

$ git branch

$ git branch -r

$ git branch -a

$ git branch [branch-name]

$ git checkout -b [branch]

$ git branch [branch] [commit]

$ git branch --track [branch] [remote-branch]

$ git checkout [branch-name]

$ git checkout -

$ git branch --set-upstream [branch] [remote-branch]

$ git merge [branch]

$ git cherry-pick [commit]

$ git branch -d [branch-name]

$ git push origin --delete [branch-name]

$ git branch -dr [remote/branch]

六、标签

七、查看信息

八、远程同步

九、撤销

十、其他

上一篇 下一篇

猜你喜欢

热点阅读