2.0 KiB
2.0 KiB
Git常用命令
-
克隆(Clone): 从远程仓库克隆一个项目到本地。
git clone <repository_url>
-
添加(Add): 将文件添加到暂存区,准备进行提交。
git add <file_name> -
提交(Commit): 将暂存区的更改提交到本地仓库,并添加提交信息。
git commit -m "Commit message" -
推送(Push): 将本地的提交推送到远程仓库。
git push origin <branch_name> -
拉取(Pull): 从远程仓库拉取最新代码到本地。
git pull origin <branch_name> -
分支(Branch): 创建、切换和查看分支。
-
创建分支:
git branch <new_branch_name> -
切换分支:
git checkout <branch_name> -
创建并切换分支(Git 2.23+):
git switch -c <new_branch_name> -
查看分支:
git branch
-
合并(Merge): 将一个分支的更改合并到另一个分支。
git merge <branch_name> -
拉取请求(Pull Request):
在远程仓库中创建一个拉取请求,请求将你的更改合并到另一个分支。
-
状态(Status): 查看工作区和暂存区的状态。
git status -
日志(Log): 查看提交历史记录。
git log -
远程仓库(Remote): 管理远程仓库的连接。
-
添加远程仓库:
git remote add <remote_name> <repository_url> -
查看远程仓库:
git remote add <remote_name> <repository_url>
-
撤销(Revert): 撤销之前的提交。
git revert <commit_hash> -
重置(Reset): 回退到指定提交,可以清空暂存区或工作区。
-
软重置,保留更改:
git reset --soft <commit_hash> -
混合重置,清空暂存区:
git reset --mixed <commit_hash> -
硬重置,清空暂存区和工作区(谨慎使用):
git reset --hard <commit_hash>
- 标签(Tag): 创建和管理版本标签。
-
创建标签:
git tag <tag_name> <commit_hash> -
查看标签:
git tag