237 字
1 分钟
Git 常用指令
2025-02-16

Git 常用指令#

  • git clone url:克隆远程仓库
  • git pull:拉取远程仓库的更新
  • git add:添加文件到暂存区
    • git add .:添加所有文件
    • git add main.c:添加特定文件
  • git commit -m "message":提交代码
  • git commit --amend -m "new message":修改提交信息

git remote set-url origin url git reset --soft HEAD~1:取消上次提交,但保留修改内容


Git Branch 分支操作#

显示所有分支

Terminal window
git branch -a

切换分支

Terminal window
git branch branch_name

创建并切换到分支

Terminal window
git checkout branch_name

合并分支

Terminal window
git branch branch_name1 # 切换到需要合并的分支
git merge branch_name2 # 将 branch_name1 合并到分支 branch_name2

Git Rmote 远程仓库#

git push 每次都需要密码,可以通过下面两种方式解决

git 远程仓库的地址为 ssh 格式,而不是 http格式

Terminal window
git remote set-url origin git@gitlab.example.com:user/remote.git

http 格式可以通过凭证助手缓存账号和密码

Terminal window
git config --global credential.helper wincred
# 或者
git config --global credential.helper store
Git 常用指令
https://fuwari.vercel.app/posts/工具/git-常用指令/
作者
Asuwee
发布于
2025-02-16
许可协议
CC BY-NC-SA 4.0