Git常用命令
git本地仓库
命令 | 作用 | 备注 |
---|---|---|
git init | 初始化本地仓库 | |
git add < file > | 添加修改 | 把修改的内容提交到暂存区 |
git commit -m < message > | 提交修改 | 把暂存区的内容提交到当前分区 |
git diff | 查看修改 | |
git restore < file > | 撤销工作区修改 | |
git restore --staged < file > | 撤销暂存区修改 | |
git rm < file > | 删除文件 | |
git status | 查看状态 | |
git log | 查看日志 | 如果要显示的内容过多,按'q'键可退出分页显示 |
git reflog | 查看历史命令 | |
git reset | 回退版本 | 可设置参数: --hard <版本号,如:601934****>,回退到指定的版本 --hard HEAD~<N,如:1、2、3...>,以HEAD为基准回退N个版本 |
git远程仓库
命令 | 作用 | 备注 |
---|---|---|
git remote add master git@github.com:***o/learngit.git | 本地仓库关联远程仓库 | |
git push -u master master | 把本地仓库内容推送到远程仓库 | 第一次 |
git push | 把本地仓库内容推送到远程仓库 | 后续 |
git remote -v | 查看关联的远程仓库版本 | |
git remote rm master | 删除关联的远程仓库 | 解除本地仓库与远程仓库的关联关系 |
常见问题
- Q: git@github.com: Permission denied (publickey). fatal: Could not read from remote repository.
- A: 执行 ssh-keygen -t rsa -C "youremail@example.com"
把生成的id_rsa.pub文件中的内容添加到远程仓库中
- A: 执行 ssh-keygen -t rsa -C "youremail@example.com"