Git 常用操作
版本控制常用命令
Git 全局设置
git config --global user.name "Example User"
git config --global user.email "user@example.com" 已有仓库?
cd existing_git_repo
git remote add origin https://github.com/user/repo.git
git push -u origin "master" 创建 git 仓库
mkdir project-name
cd project-name
git init
touch README.md
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/user/repo.git
git push -u origin "master" 常用命令速查
| 命令 | 说明 |
|---|---|
git clone <url> | 克隆远程仓库 |
git status | 查看工作区状态 |
git add . | 暂存所有修改 |
git add <file> | 暂存指定文件 |
git commit -m "msg" | 提交并添加说明 |
git push | 推送到远程 |
git pull | 拉取远程更新 |
git branch | 查看本地分支 |
git branch -a | 查看所有分支 |
git checkout -b <branch> | 创建并切换分支 |
git checkout <branch> | 切换分支 |
git merge <branch> | 合并指定分支 |
git log --oneline | 简洁查看提交历史 |
git diff | 查看未暂存修改 |
git stash | 暂存当前修改 |
git stash pop | 恢复暂存的修改 |
git reset --soft HEAD~1 | 撤销最近一次提交(保留修改) |