Content
basic file operation
command | describe |
---|---|
git init | |
git add . | |
git commit -m “” | |
git push origin [branch_name] | |
git commit -am "" | |
git commit -amend | 修改最近一次的commit信息 |
git rm --cached * | 移除暂缓的追踪, 适用于修改了.gitignore时 |
git pull origin master:dev | 拉取远程主机的master分支合并到本地dev分支 |
git status | 查看状态 |
git diff | 工作区 vs 暂存区 |
git diff --cache | 暂存区 vs 版本库当前分支 |
branch operation
command | describe |
---|---|
git remote add origin master | 本地主分支关联远程主分支 |
git remote rm origin | 取消关联 |
git branch | 查看本地分支 |
git branch -r | 查看远程分支 |
git branch -a | 查看所有分支(local and remote) |
git branch [branch_name] | 新建分支 |
git checkout [branch_name] | 切换分支 |
git branch -d [branch_name] | 删除本地分支 |
git push origin :[remote_branch_name] or git push origin --delete [branch_name] | 删除远程分支. 注意第一种方法远程分支名前有一个冒号 |
git branch -m [old_name] [new_name] | 本地分支更名 |
git push --set-upstream origin new_branch or git push -u origin new_branch | 本地分支与远程分支添加关联 |
version repository operation
command | describe |
---|---|
git log | 查看提交记录 |
git reflog | 查看发送过的命令日志 |
git show [commit_id] | 查看某次提交的更改. |
git reset --soft HEAD^ | 撤回到上一个版本库, 暂存区和工作区不变. .即撤回到上次提交, 并保留代码. 等价HEAD~1 , 亦可为commit_id |
git reset (–mixed) HEAD^ | 撤回到上一个版本库, 上一个暂存区. 即撤回到上次未add未commit时. |
git reset --hard HEAD^ | 撤回到上一个版本库, 上一个暂存区, 上一个工作区. 即完全撤回到上次提交的状态(不保留任何更改) |
git restore (--worktree) [file_name] | 撤销工作区 对于暂缓区的更改 |
git restore --staged [file_name] | 撤销暂缓区 对于版本库的更改 |
git restore --worktree --staged [file_name] | 叠加 |
git checkout -- [file_name] | 从暂存区恢复文件. 注意两个横线 |
git reset HEAD [file_name] | 从版本库中恢复文件到暂缓区 |
git rm -r --cached dir_or_file_name | 移除暂存区更改. 亦可 reset. |
git clean | 清除暂缓区更改 |
git stash | |
git stash list | |
git stash pop ([–index]) ([id]) | |
git stash drop [id] | |
git stash clear | 清除所有 |