304 字
2 分钟
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 branch1git checkout branch1# 或合并成下面:git checkout -b branch1将 branch2 合并到 branch1 上
git checkout branch1 # 切换到需要合并的分支git merge branch2 # 将 branch_name2 合并到 branch1 上将 branch2 合并到 branch1 上,但需要忽略 branch2 的所有更改
git checkout branch1git merge -s ours branch2# -s ours 表明在合并分支时,完全忽略对方分支(branch2)的更改Git Rmote 远程仓库
git push 每次都需要密码,可以通过下面两种方式解决
git 远程仓库的地址为 ssh 格式,而不是 http格式
git remote set-url origin git@gitlab.example.com:user/remote.githttp 格式可以通过凭证助手缓存账号和密码
git config --global credential.helper wincred# 或者git config --global credential.helper store