Git 常用命令

425 字
2 分钟
Git 常用命令
Git 常用命令

Git#

  1. 基础

    Terminal window
    git config --list
    git config --global user.name "你的名字"
    git config --global http.proxy http://127.0.0.1:7897
    git init
    git status
    git add .
    git commit -m "test"
    git diff ##只看到未add的文件的更改
    git pull
    git push ##push前记得pull
    git push -f ##强制更新
    git push -u origin main ##将当前分支和远程分支关联起来然后推送
    git clone url
  2. 分支

    Terminal window
    git branch -vv ##当前哪个分支以及远程对应的分支
    git branch -a ##一共多少分支
    git branch
    git branch -M main ##修改当前分支名字
    git checkout main ##切换分支为main
    git checkout -b newBranch ##从当前分支切出新的本地分支newBranch
    git branch -D newBranch ##删除本地分支newBranch,当前分支不能是newBranch
    git push origin --delete newBranch ##删除远程分支
    git push origin newBranch ##将本地分支newBranch推送到origin的newBranch分支上,不存在就创建
    git branch --set-upstream-to=origin/newBranch ##把本地分支newBranch绑定到远程newBranch,或者可以在上一条命令加上-u参数就可以自动绑定,如果不绑定push和pull都要在后面加上origin newBranch
    git merge newBranch ##将newBranch合并到当前分支,,远程没有合并,还需要push
    git rebase newBranch
    git remote -v
    git remote add origin url ##设定远程仓库
    git remote set-url origin url ##修改远程仓库
  3. 恢复

    Terminal window
    git checkout . ##撤销未add的代码
    git reset --mixed ##撤销已经add的代码
    git reset --soft HEAD^ ##撤销已经commit的代码
    git reset --soft HEAD^ ##撤销commit和add的代码
  4. stash(每个本地分支都能看到)

    Terminal window
    git stash list
    git stash save newStash
    git stash pop stash@{1}
  5. 版本管理

    Terminal window
    git log
    git log --graph --oneline ##好看输出
    git reset --hard 版本号码

文章分享

如果这篇文章对你有帮助,欢迎分享给更多人!

Git 常用命令
https://www.serein0329.top/posts/linux/git/
作者
Serein0329
发布于
2026-10-11
许可协议
CC BY-NC-SA 4.0
Profile Image of the Author
Serein0329
并非命运塑造了我们,而是我们塑造了命运。
公告
欢迎来到我的博客!本博客分享技术知识与个人唠嗑...
分类
标签
最新动态
站点统计
文章
4
分类
2
标签
4
总字数
1,983
运行时长
0 天
最后活动
0 天前
站点信息
构建平台
Local
博客版本
Firefly v6.16.8
文章许可
CC BY-NC-SA 4.0
文章目录