Skip to content

提交代码一系列操作

进入到要提交的文件夹,右键git Bash

sh
git add .
git status
git commit -m "提交说明"
git push
git add .
git status
git commit -m "提交说明"
git push

提交全部修改文件

sh
git add .
git commit -m "提交说明"
git add .
git commit -m "提交说明"

提交指定文件/一次性提交多个指定文件

sh
git add path/to/file1 path/to/file2
git commit -m "提交说明"
git add path/to/file1 path/to/file2
git commit -m "提交说明"

重置add和commit的代码

  • 取消暂存(撤销 add)
sh
git reset HEAD path/to/file
git reset HEAD path/to/file
  • 撤销上一次 commit(但保留修改)
sh
git reset --soft HEAD~1
git reset --soft HEAD~1
  • 撤销 commit 和暂存(保留修改)
sh
git reset --mixed HEAD~1
git reset --mixed HEAD~1
  • 撤销 commit 和修改(危险操作)
sh
git reset --hard HEAD~1
git reset --hard HEAD~1

拉取指定分支代码

sh
git pull origin 分支名
git pull origin 分支名

查看所有分支

sh
git branch        # 查看本地分支
git branch -r     # 查看远程分支
git branch -a     # 查看所有分支(本地+远程)
git branch        # 查看本地分支
git branch -r     # 查看远程分支
git branch -a     # 查看所有分支(本地+远程)

切换分支

sh
git checkout 分支名
git switch 分支名 # 新版命令
git checkout 分支名
git switch 分支名 # 新版命令

删除指定分支

sh
git branch -d 分支名     # 删除本地分支(已合并)
git branch -D 分支名     # 强制删除本地分支
git push origin --delete 分支名   # 删除远程分支
git branch -d 分支名     # 删除本地分支(已合并)
git branch -D 分支名     # 强制删除本地分支
git push origin --delete 分支名   # 删除远程分支

新建分支

sh
git branch 新分支名
git checkout 新分支名
git branch 新分支名
git checkout 新分支名

或者

sh
git checkout -b 新分支名
git checkout -b 新分支名

查看状态

sh
git status
git status

查看提交日志

sh
git log --oneline --graph --decorate --all
git log --oneline --graph --decorate --all

推送分支到远程

sh
git push origin 分支名
git push origin 分支名

合并分支

sh
git merge 分支名
git merge 分支名

撤销文件修改(回退到上次提交)

sh
git checkout -- path/to/file
git checkout -- path/to/file