Git的有些命令已经融入到血液中,通常情况下大脑可能还没有想出来,键盘却已经敲出来了。 但是同样有一些Git命令,平时用不上,但真正遇到了使用场景时,却怎么也想不起来,不得不面向CSDN编程。 比如有时候git commit 的提交说明手残打错了, 想要回撤总也想不起来怎么搞。在多次踩坑之后,我特意整理了这几个命令,可能几个月也用不上,记忆成本也不到,但是如果不知道,有时还挺恼火~ ~ 诸君共勉。
批量删除远程分支
git branch -a | grep remote | grep ogenes | awk -F '/' '{print $3"/"$4"/"$5}' | xargs git push origin --delete
修改最近一次 git commit 内容
git commit --amend
取消最近一次提交,并保留文件更改
git reset --mixed head~1
更新远程分支
git remote update origin --prune
➜ ogenes-permission git:(main) git remote update origin --prune
Fetching origin
From github.com:ogenes/ogenes-permission
- [deleted] (none) -> origin/pro
远程仓库改名
git remote rename origin ogenes
多个仓库地址
-
查看远程仓库
➜ docker-lnmp git:(main) git remote -v ogenes git@github.com:ogenes/docker-lnmp.git (fetch) ogenes git@github.com:ogenes/docker-lnmp.git (push) origin git@gitlab.ogenes.cn:john.yi/docker-lnmp.git (fetch) origin git@gitlab.ogenes.cn:john.yi/docker-lnmp.git (push)
-
删除一个远程仓库
➜ docker-lnmp git:(main) git remote rm ogenes ➜ docker-lnmp git:(main) git remote -v origin git@gitlab.ogenes.cn:john.yi/docker-lnmp.git (fetch) origin git@gitlab.ogenes.cn:john.yi/docker-lnmp.git (push)
-
新增一个远程仓库
➜ docker-lnmp git:(main) git remote add ogenes git@github.com:ogenes/docker-lnmp.git ➜ docker-lnmp git:(main) git remote -v ogenes git@github.com:ogenes/docker-lnmp.git (fetch) ogenes git@github.com:ogenes/docker-lnmp.git (push) origin git@gitlab.ogenes.cn:john.yi/docker-lnmp.git (fetch) origin git@gitlab.ogenes.cn:john.yi/docker-lnmp.git (push)
-
修改远程仓库地址
➜ docker-lnmp git:(main) git remote set-url origin git@gitlab.ogenes.cn/docker-lnmp.git ➜ docker-lnmp git:(main) git remote -v ogenes git@github.com:ogenes/docker-lnmp.git (fetch) ogenes git@github.com:ogenes/docker-lnmp.git (push) origin git@gitlab.ogenes.cn/docker-lnmp.git (fetch) origin git@gitlab.ogenes.cn/docker-lnmp.git (push)
-
推送到指定仓库
➜ docker-lnmp git:(feature/ogenes) git push ogenes feature/ogenes Enumerating objects: 9, done. Counting objects: 100% (9/9), done. Delta compression using up to 8 threads Compressing objects: 100% (6/6), done. Writing objects: 100% (6/6), 603 bytes | 603.00 KiB/s, done. Total 6 (delta 4), reused 0 (delta 0), pack-reused 0 remote: Resolving deltas: 100% (4/4), completed with 3 local objects. remote: remote: Create a pull request for 'feature/ogenes' on GitHub by visiting: remote: https://github.com/ogenes/docker-lnmp/pull/new/feature/ogenes remote: To github.com:ogenes/docker-lnmp.git * [new branch] feature/ogenes -> feature/ogenes
-
从指定仓库拉取
➜ docker-lnmp git:(main) git pull ogenes
From github.com:ogenes/docker-lnmp
* [new branch] main -> ogenes/main
You asked to pull from the remote 'ogenes', but did not specify
a branch. Because this is not the default configured remote
for your current branch, you must specify a branch on the command line.
git pull 报错 refusing to merge unrelated histories
➜ exceler git:(master) git pull
fatal: refusing to merge unrelated histories
➜ exceler git:(master) git pull origin master --allow-unrelated-histories