git
git
git filter-branch --index-filter "git rm --cached --ignore-unmatch *.lib *.dll *.exe *.ttf *.bmp *.sdf *.ipch *.ncb" --prune-empty -f HEAD --all
rm -Rf refs/original
rm -Rf logs/
git gc
git repack
git repack -adf
git prune-packed
git prune
Determine if Git working directory is clean from a script
#! /bin/bash
for D in $PWD/$1/*/ ; do
cd $D
git diff-files --exit-code &> /dev/null
if [ $? -ne 0 ] ; then
# Working directory clean
echo $D
git status -s
#else
# Uncommitted changes
fi
cd $PWD
done
Compares files in the working tree and the index
git diff-files --exit-code
Migrate history to or from git-lfs
First, run git lfs migrate info to list the file types taking up the most
space in your repository.
$ git lfs migrate info
Now, you can run git lfs migrate import to convert some file types to LFS:
$ git lfs migrate import --include="*.mp3,*.psd"
You can also migrate the entire history of your repository:
# Check for large files in your local master branch
$ git lfs migrate info --include-ref=master
# Check for large files in every branch
$ git lfs migrate info --everything
The same flags will work in import mode:
# Convert all zip files in your master branch
$ git lfs migrate import --include-ref=master --include="*.zip"
# Convert all zip files in every local branch
$ git lfs migrate import --everything --include="*.zip"
LFS 使用 info 模式检查历史文件
要查看 应被 Git LFS 跟踪但尚未跟踪的历史文件(即符合 .gitattributes 规则但未转换为 LFS 的文件),请使用:
git lfs migrate info --everything
关键说明:
-
作用:
- 此命令会扫描所有分支的历史提交(
--everything表示包括所有本地和远程引用)。 - 输出按文件类型(扩展名)汇总 应被 LFS 跟踪但实际未被跟踪的文件(即未转换为 LFS 指针的二进制文件)。
- 示例输出:
*.psd 150 MB 3 files
*.zip 80 MB 2 files
- 此命令会扫描所有分支的历史提交(
-
依赖
.gitattributes:- 命令会自动读取仓库根目录的
.gitattributes文件中的规则(如*.psd filter=lfs)。 - 确保您的
.gitattributes已提交到仓库 。
- 命令会自动读取仓库根目录的
-
限制范围:
- 若仓库较大,可限定检查的分支:
git lfs migrate info --include-ref=main # 仅检查 main 分支
- 若仓库较大,可限定检查的分支:
实际迁移操作
确认文件后,执行实际迁移(务必先备份仓库):
git lfs migrate import --everything --include="*.psd,*.zip"
git push --force --all # 重写历史后强制推送
注意事项:
- 协作者需重新克隆:历史重写后,所有协作者必须重新克隆仓库。
Finds best common ancestor(s) between two commits to use in a three-way merge.
git merge-base [-a|--all] <commit> <commit>…
Github Copilot
curl --verbose https://copilot-proxy.githubusercontent.com/_ping
Three way merge by git
1. get parent of two branch
git merge-base origin/src_branch origin/target_branch
2. clone 4 dirs
base src_branch target_branch out
3. merge from src_branch to target_branch
cd out
git checkout target_branch
git pull origin src_branch -X theirs
4. FolderMerge by Beyond Compare
left folder is target_branch