Git 常用命令
425 字
2 分钟
Git 常用命令
Git
-
基础
Terminal window git config --listgit config --global user.name "你的名字"git config --global http.proxy http://127.0.0.1:7897git initgit statusgit add .git commit -m "test"git diff ##只看到未add的文件的更改git pullgit push ##push前记得pullgit push -f ##强制更新git push -u origin main ##将当前分支和远程分支关联起来然后推送git clone url -
分支
Terminal window git branch -vv ##当前哪个分支以及远程对应的分支git branch -a ##一共多少分支git branchgit branch -M main ##修改当前分支名字git checkout main ##切换分支为maingit checkout -b newBranch ##从当前分支切出新的本地分支newBranchgit branch -D newBranch ##删除本地分支newBranch,当前分支不能是newBranchgit push origin --delete newBranch ##删除远程分支git push origin newBranch ##将本地分支newBranch推送到origin的newBranch分支上,不存在就创建git branch --set-upstream-to=origin/newBranch ##把本地分支newBranch绑定到远程newBranch,或者可以在上一条命令加上-u参数就可以自动绑定,如果不绑定push和pull都要在后面加上origin newBranchgit merge newBranch ##将newBranch合并到当前分支,,远程没有合并,还需要pushgit rebase newBranchgit remote -vgit remote add origin url ##设定远程仓库git remote set-url origin url ##修改远程仓库 -
恢复
Terminal window git checkout . ##撤销未add的代码git reset --mixed ##撤销已经add的代码git reset --soft HEAD^ ##撤销已经commit的代码git reset --soft HEAD^ ##撤销commit和add的代码 -
stash(每个本地分支都能看到)
Terminal window git stash listgit stash save newStashgit stash pop stash@{1} -
版本管理
Terminal window git loggit log --graph --oneline ##好看输出git reset --hard 版本号码
文章分享
如果这篇文章对你有帮助,欢迎分享给更多人!














