【SE笔记】Git的基本使用

获得Github的授权

这篇文章来使用优雅的凭证管理办法。

基操

  • 拉取最新更改,以免冲突 - git pull origin <Branch>
  • 将文件添加到暂存区 - git add <FileName> # 添加所有文件是 git add ./
  • 显示有变动的文件 - git status
  • 提交更改 - git comment -m "<Note>"
  • 推送更改 - git push origin <Branch>
  • 切换分支 - git checkout <Branch>
  • 新建分支 - git checkout -b <NewBranch>
  • 删除分支 - git branch -d <Branch>
  • 删除远程分支 - git push origin --delete <Branch>
  • 合并分支 - git merge <Another Branch>

其他操作

  • 查看工作区和暂存区文件的差异 - git diff
  • 查看commit记录 - git log --oneline
  • 以图标形式查看commit记录 - git log --graph
  • 回滚commit - git reset --hard/soft/mixed <Commit>
  • 恢复工作区的文件到最新状态 - git restore <FileName>
  • 恢复暂存区的文件到最新状态 - git restore --staged <FileName>
  • 恢复指定commit的文件 - git restore --source=<Commit> --worktree <FileName>
  • 删除暂存区的文件 - git rm --cache <FileName>
  • 查看commit的详细信息 - git show <Commit>
  • 如果要保留空文件夹,就再需要保留的文件夹下面新建一个文件叫.gitkeep,或者随便建一个文件,反正文件夹就是不能空

【SE笔记】Git的基本使用
https://study.0x535a.cn/se-note/se-git/
Author
Stephen Zeng
Posted on
October 4, 2024
Licensed under