237 字
1 分钟
Git 常用指令
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 分支操作
显示所有分支
git branch -a
切换分支
git branch branch_name
创建并切换到分支
git checkout branch_name
合并分支
git branch branch_name1 # 切换到需要合并的分支git merge branch_name2 # 将 branch_name1 合并到分支 branch_name2
Git Rmote 远程仓库
git push
每次都需要密码,可以通过下面两种方式解决
git 远程仓库的地址为 ssh 格式,而不是 http格式
git remote set-url origin git@gitlab.example.com:user/remote.git
http 格式可以通过凭证助手缓存账号和密码
git config --global credential.helper wincred# 或者git config --global credential.helper store