一些关于 Git 的使用笔记 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364# 文档&教程# https://git-scm.com/# https://github.com/# https://docs.github.com/en/repositories/creating-and-managing-repositories/creating-a-new-repository# https://www.runoob.com/git/git-tutorial.html# github cli 使用# https://cli.github.com/manual/# 使用 gh 登陆gh auth login# 创建新仓库,并推送至远程地址echo "# your repo name" >> README.mdgit initgit add README.mdgit commit -m "first commit"git branch -M maingit remote add origin https://github.com/your-github-account-name/your-new-repo.gitgit push -u origin main# 已有 repogit remote add origin https://github.com/your-github-account-name/your-new-repo.gitgit branch -M maingit push -u origin main# 在已有仓库创建新 branchgit checkout -b newBranchgit add *git commit -m "init commit"git push origin newBranch# 查看已有分支git branch -a# 丢弃未提交的更改git checkout .# commit 时带上其他人git commit --author="aaa <[email protected]>" -a -m "xxxxxxxxxxxxCo-authored-by: bbb <[email protected]>Co-authored-by: ccc <[email protected]>"# 切换代码版本git checkout "可以是tag、branch,也可以是当前分支下的 commit sha"# 查看未提交的代码与原代码的差异git diff# 删除远程分支git push origin -d remote_branch# git 修改 commit# https://segmentfault.com/a/1190000041122415# https://juejin.cn/post/6844903806224826375git rebase -i "你需要修改的 commit 的前一个 commit" (接着会跳出编辑器页面,把需要修改的 commit 的 "pick" 改成 "edit")git commit --amend (还可以附带参数,如:--author="Author Name <[email protected]>")# 如果你已经修改了 git config 中的用户名和邮箱,也可以使用:git commit --amend --reset-author --no-editgit rebase --continue (移动到下个 commit 作为基准)git push -f......