一些关于 Git 的使用笔记 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253# 文档&教程# 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 "可以是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......