基本配置和初始化
1. 配置用户名:
git config --global user.name "Your Name"
2. 配置用户邮箱:
git config --global user.email "your.email@example.com"
3. 初始化一个新仓库:
git init
基本操作
4. 检查当前文件状态:
git status
5. 添加文件到暂存区:
git add <file>
6. 提交暂存区的文件到本地仓库:
git commit -m "Your commit message"
7. 查看提交历史:
git log
分支操作
8. 创建新分支:
git branch <branch_name>
9. 切换到分支:
git checkout <branch_name>
或者(Git 2.23+):
git switch <branch_name>
10. 创建并切换到新分支:
git checkout -b <branch_name>
或者:
git switch -c <branch_name>
11. 合并分支:
git merge <branch_name>
12. 删除分支:
git branch -d <branch_name>
远程仓库
13. 添加远程仓库:
git remote add <remote_name> <remote_url>
14. 拉取远程仓库的更新:
git pull <remote_name> <branch_name>
15. 推送本地提交到远程仓库:
git push <remote_name> <branch_name>
撤销和修改
16. 撤销工作区的修改:
git checkout -- <file>
17. 撤销暂存区的修改:
git reset HEAD <file>
18. 修改最后一次提交:
git commit --amend
其他
19. 查看远程仓库列表:
git remote -v
20. 查看分支列表:
git branch
21. 查看帮助:
git --help
以上是一些常见的 Git 命令,这只是 Git 功能的冰山一角。根据具体的工作流程和需求,你可能会使用到更多的 Git 命令和选项。
转载请注明出处:http://www.zyzy.cn/article/detail/10606/Git