当然!以下是一份 Git 命令的大全:
-
创建和克隆仓库:
- git init:初始化一个新的 Git 仓库。
- git clone <repository>:从远程仓库克隆一个本地副本。
-
基本操作:
- git add <file>:将文件添加到暂存区。
- git commit -m "message":将暂存区的文件提交到本地仓库,并添加提交信息。
- git status:查看当前仓库状态。
- git diff:查看未暂存的文件变化。
-
分支管理:
- git branch:列出所有分支。
- git branch <branch-name>:创建新分支。
- git checkout <branch-name>:切换到指定分支。
- git merge <branch-name>:将指定分支合并到当前分支。
- git branch -d <branch-name>:删除指定分支。
-
远程仓库:
- git remote add <name> <url>:添加远程仓库。
- git remote -v:查看远程仓库列表。
- git push <remote> <branch-name>:将本地仓库中的代码推送到远程仓库。
- git pull <remote> <branch-name>:从远程仓库拉取最新代码并合并到本地仓库。
-
撤销和回退:
- git revert <commit>:撤销指定提交。
- git reset <commit>:回退到指定提交,丢弃后续提交。
- git reset --hard <commit>:回退到指定提交,丢弃后续提交和工作目录的改动。
-
日志和历史:
- git log:查看提交日志。
- git log --oneline:以简洁方式查看提交日志。
- git log --graph:以图形化方式查看提交历史。
-
其他常用命令:
- git stash:将当前的修改保存到临时存储区。
- git stash apply:恢复最近的一次临时存储区的修改。
- git blame <file>:显示指定文件的每一行是谁修改的。
这只是 Git 命令的一小部分,你可以通过 git --help
或者 git <command> --help
来获取更详细的命令说明和用法。祝你在使用 Git 过程中顺利!