Git的常用命令

80 阅读1分钟
  1. 初始化仓库
	git init
  1. 添加文件到暂存区
	git add <file>
  1. 添加所有文件到暂存区
	git add .
  1. 提交更改
	git commit -m "Commit message"
  1. 查看提交历史
	git log
  1. 克隆仓库
	git clone <repository-url>
  1. 查看当前分支
	git branch
  1. 切换分支
	git checkout <branch-name>
  1. 创建新分支
	git branch <branch-name>
  1. 合并分支
	git merge <branch-name>
  1. 删除分支
  • 删除已经合并的分支:
	git branch -d <branch-name>
  • 强制删除未合并的分支(小心使用):
	git branch -D <branch-name>
  1. 查看更改
  • 查看工作目录中的更改:
	git status
  • 查看未暂存的更改:
	git diff
  • 查看已暂存的更改:
	git diff --staged
  1. 撤销更改
  • 撤销最后一次提交(撤销工作目录中的更改):
	git reset --soft HEAD^1
  • 撤销暂存区的更改:
	git reset <file>
  • 撤销工作目录和暂存区的更改:
	git checkout -- <file>