git 命令手册【不定时更新】
操作
-
本地分支 --> 远程服务器
git add xxx
git rm -rf xxx
git commit -m "xxx"
git push origin xxx -
远程服务器 --> 本地分支
git pull origin xxx -
错误push到远程服务器,但想撤回
git log --oneline
git reset --hard xxx
git push --force origin main -
push时发生冲突
(1)当执行 git push 时,Git 发现本地分支和远程分支的历史不一致,因此拒绝推送,并建议你先拉取远程更改。
(2)当执行 git pull 时,Git 会尝试将远程分支的更改合并到你的本地分支。
(3)如果本地分支和远程分支都有新的提交,Git 会创建一个合并提交(merge commit)来整合两者的更改。这个合并提交的标题通常是 Merge branch 'branch_name' of repository_url into branch_name
(4)按 Ctrl+0 保存文件,然后按 Ctrl+X 退出编辑器,这导致 Git 使用默认的合并消息生成了合并提交。
ps:如果你希望避免生成合并提交,可以在 git pull 时使用 --rebase 选项:git pull --rebase 这样 Git 会将你的本地提交“变基”到远程分支的最新提交之后,而不是生成一个合并提交。 -
将a分支上的特定提交(哈希码为 abc123456)增量应用到本地的b分支上
git checkout b
git cherry-pick abc123456
如果出现冲突,Git 会提示你手动解决。解决冲突后,使用以下命令继续:
git add <冲突文件>
git cherry-pick --continue -
查看本地分支和远程服务器上的分支信息有什么不同?
git diff --name-status xxx origin/xxx -
基于现在的分支创建一个新的分支:
git checkout -b <新分支名> -
push了一次以后,想再次push但不更改commit
git add xxx
git commit --amend
git push xxx -
将本地某个分支的内容完全替换为远程分支的内容
(1)删除本地分支(例如 watermarking)
git branch -D watermarking
(2)从远程重新拉取同名分支
git checkout -b watermarking origin/watermarking
报错
- 运行命令:git pull origin jailbreak 报错如下:
remote: Invalid username or password.
fatal: Authentication failed for 'https://github.com/S3DI-Lab/AwesomeLLMSecurityPlatform.git/'
解决方法:https://blog.csdn.net/qq_32442465/article/details/143800848
然后重新执行git pull origin jailbreak,username是你的github用户名,password是你的令牌
其他
- Commit message规范
https://blog.csdn.net/K346K346/article/details/130614289