Skip to content
李小明 edited this page Feb 17, 2023 · 37 revisions

常用

  • 克隆最新代码 git clone --depth=1 --progress https://git.ffmpeg.org/ffmpeg.git
  • 推送新的分支 git push -u origin 本地分支名字:远程分支名字
  • 创建标签 git tag -a v1.1 -m "description text"
  • 推送标签 git push --tags
  • 删除标签 TAG="v1.0" && git tag -d $TAG && git push origin tag -d $TAG
  • 设置代理 git config --global git.http.https://github.com.proxy socks5://127.0.0.1:4444
  • 取消代理 git config --global --unset git.http.https://github.com.proxy
  • 添加子模块 git submodule add git_url git_path
  • 更新子模块 git submodule update --init --recursive

推送(拉取)多个源

参考

git remote add github git@github.com:alx696/android-map.git
git remote set-url --add --push origin git@github.com:alx696/android-map.git
git remote set-url --add --push origin git@codeup.aliyun.com:5f9f9bd3e89148238ce7f523/android-map.git

github 是github库的别名. 设置远程推送后记得把主库补上, 否则将只会推送到后设置的那个.

如此设置之后, 推送时会同时向两个库推送. 但是拉取还是只能从一个库拉取, 要全部拉取可以执行git fetch --all.

注意: git fetch --all不会更新当前分支, 需要手动合并. 一般不要使用, 以一个库为主, 添加的作为备份.

最终示例:

[remote "origin"]
	url = ssh://git@git.lilu.red:83/root/po_long_flutter.git
	fetch = +refs/heads/*:refs/remotes/origin/*
	pushurl = ssh://git@git.lilu.red:83/root/po_long_flutter.git
	pushurl = git@github.com:alx696/po_long_flutter.git
[remote "github"]
	url = git@github.com:alx696/po_long_flutter.git
	fetch = +refs/heads/*:refs/remotes/origin/*
[branch "main"]
	remote = origin
	merge = refs/heads/main

参考

删除文件及其历史(彻底删除)

git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch gomobile/gomobile.aar' --prune-empty --tag-name-filter cat -- --all
git push origin master --tags --force

需在Git库根目录执行, gomobile/gomobile.aar为要删除文件路径.

拉取指定内容

git init temp && cd temp
git remote add origin git@github.com:alx696/go-ptp.git
git config core.sparseCheckout true
echo "web/" >> .git/info/sparse-checkout
git pull --depth=1 origin main

添加到.git/info/sparse-checkout中的就是指定内容。

GitHub

Android密钥在Action中的使用

参考 使用GPG先将密钥文件 lilu.red.jks 加密成密文, 然后将密文配置到项目 Actions secrets 中, 在使用时再将密文还原成密钥文件.

密钥加密成密文:

gpg -c --armor lilu.red.jks

执行后会要求输入密码, 输入密码后会生成密文文件 lilu.red.jks.asc .

将密文和密码配置项目的 Actions secrets 中:

  • ANDROID_JKS_GPG 密文
  • ANDROID_JKS_GPG_PASSWORD 密码

使用时在Action的yml中还原密钥即可:

echo "${{ secrets.ANDROID_JKS_GPG }}" | tee android/app/lilu.red.jks.asc
gpg -d --passphrase "${{ secrets.ANDROID_JKS_GPG_PASSWORD }}" --batch android/app/lilu.red.jks.asc > android/app/lilu.red.jks

免密SSH模式

  1. 生成密钥:
ssh-keygen -t ed25519 -f ~/.ssh/id_ed25519 -C alx696@gmail.com && chmod 400 ~/.ssh/id_ed25519 && cat ~/.ssh/id_ed25519.pub
ssh-keyscan -t ed25519 github.com > ~/.ssh/known_hosts

生成密钥时设置密码, 否则存在私钥被盗用风险!

  1. 复制输出的"ssh-ed25519"到末尾的这段字符, 到 https://github.com/settings/ssh/new 粘贴设置并点击“Add SSH Key”.

  2. 以SSH方式克隆库(如果库已经以HTTPS模式克隆到本地了, 则进入.git/config中将远程地址修改成ssh的即可).

安装

sudo add-apt-repository ppa:git-core/ppa ; \
sudo apt update ; \
sudo apt install -y git

设置

邮箱和名字

git config --global user.email alx696@gmail.com ; \
git config --global user.name "李小明" ; \
git config --global pull.rebase false ; \
git config --global init.defaultBranch main ;\
git config --global git.http.https://github.com.proxy socks5://127.0.0.1:4444