Git常用命令总结
1.基本操作
- 初始化:
git init - 设置用户名:
git config --global user.name 用户名 - 设置邮箱:
git config --global user.email 邮箱 - 查看用户名:
git config user.name - 查看邮箱:
git config user.email - 克隆:
git clone 仓库地址 - 查看状态:
git status - 获取:
git fetch - 拉取:
git pull - 提交:
git add 文件 - 提交更改:
git commit -m 提交信息 - 推送:
git push origin 分支名 - 查看历史:
git log
2.分支管理
- 查看分支:
git branch - 创建分支:
git branch 分支名 - 切换分支:
git checkout 分支名 - 创建切换:
git checkout -b 分支名 - 合并分支:
git merge 分支名 - 删除分支:
git branch -d 分支名 - 强删除分支:
git branch -D 分支名
3.远程操作
- 查看远程仓库:
git remote -v - 添加远程仓库:
git remote add 远程仓库名 远程仓库地址 - 拉取远程分支:
git fetch - 拉取合并远程分支:
git pull 远程仓库名 分支名 - 合并拉取远程分支:
git pull 远程仓库名 分支名 --allow-unrelated-histories - 推送到远程分支:
git push 远程仓库名 分支名 - 强制推送远程分支:
git push -f 远程仓库名 分支名
4.高级命令
- 撤销文件:
git reset 文件 - 撤销所有文件:
git reset --hard - 暂存当前更改:
git stash - 暂存最近更改:
git stash apply - 查看差异:
git diff - 查看提交差异:
git diff --cached - 撤销目录更改:
git checkout 文件 - 重置暂存更改:
git reset 文件 - 重置所有更改:
git reset --hard
- 感谢你赐予我前进的力量
赞赏者名单
因为你们的支持让我意识到写文章的价值🙏
本文是原创文章,版权归阁主所有。转载本文请联系阁主。
评论
匿名评论
隐私政策
你无需删除空行,直接评论以获取最佳展示效果