快速导航
常见问题
配置大小写敏感
全局配置
1git config --global core.ignorecase false
临时生效
1git mv --force dockerfile Dockerfile
git修改提交作者和邮箱
-
提交前 如果代码未提交,则可以
1git config user.name "Author Name" 2git config user.email "Author Email" -
提交后 如果代码已经提交,或者已经push到remote(只能修改最近一次提交)
1git commit --amend --author="NewAuthor <[email protected]>"修改全部commit,需要使用脚本 参考github官方
1#!/bin/sh 2 3git filter-branch --env-filter ' 4OLD_EMAIL="[email protected]" 5CORRECT_NAME="Your Correct Name" 6CORRECT_EMAIL="[email protected]" 7if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ] 8then 9 export GIT_COMMITTER_NAME="$CORRECT_NAME" 10 export GIT_COMMITTER_EMAIL="$CORRECT_EMAIL" 11fi 12if [ "$GIT_AUTHOR_EMAIL" = "$OLD_EMAIL" ] 13then 14 export GIT_AUTHOR_NAME="$CORRECT_NAME" 15 export GIT_AUTHOR_EMAIL="$CORRECT_EMAIL" 16fi 17' --tag-name-filter cat -- --branches --tags在.git同级目录下运行
1sh git.sh然后使用
--forcepush到远程
合并多个commit历史
1git rebase -i commit_id
使用 magit
1magit-status
2ll
3# move to commit id
4r-ii
git删除远程分支已经被删除的本地分支
也不知道为什么, google了很久也没找到答案,明明题目已经清楚的问
如何删除远程分支已经被删除的本地分支?
可下面一群人在答
如何删除本地分支已经被删除的远程分支?
瞎答
最后还是只能靠自己
1# 先清理远程分支, 即删除本地分支已经被删除的远程分支
2git fetch -p
3# 找到存在的远程分支
4git branch -r | grep -v HEAD | awk -F '/' '{print $2}' > /tmp/test.txt
5# 清理本地分支
6git branch -a | grep -v '\*' | egrep -v -f /tmp/test.txt | xargs git branch -d
注意: 不要使用 xargs git branch -D
合并pull request
1git fetch origin pull/3/head:pr
2git checkou pr
fork版本保持与上游一致
https://github.com/selfteaching/the-craft-of-selfteaching/issues/67
1git remote -v
2git remote add upstream 上游仓库url(git@...)
3git fetch upstream
4git rebase upstream/master # 可能会提示:首先,回退头指针以便在其上重放您的工作...
5git reset upstream/master --hard
镜像站
1git config --global url.https://github.com.cnpmjs.org/.insteadof https://github.com/
报错
error: pathspec 'py3' did not match any file(s) known to git.
1# git checkout py3
2error: pathspec 'py3' did not match any file(s) known to git.
3# git branch -a
4* master
5 remotes/origin/HEAD -> origin/master
6 remotes/origin/master
-
解决方式
1# git config --get remote.origin.fetch 2+refs/heads/master:refs/remotes/origin/master 3# git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*" 4# git config --get remote.origin.fetch 5+refs/heads/*:refs/remotes/origin/*然后重新
git fetch即可
知识共享署名-非商业性使用-相同方式共享4.0国际许可协议