使用本地 Git LFS 存储库检查是否有任何文件在未复制的情况下更改。git
Use local Git LFS repo to check if any file changed without copying under .git
我有一个包含大量二进制文件的文件夹。我想 保存 当前状态,进行一些更改并查看 git status
更改了哪些文件。我认为使用 Git LFS 是个好主意,因为它只为每个文件保留 3 行大小和哈希信息。
问题是 git add .
命令需要很多时间并进行备份。是否可以只提交指针文件而不创建 LFS 对象?
我使用的命令:
$ git init
$ git lfs install
$ git lfs track "*"
$ echo ".gitattributes filter= diff= merge= text" >> .gitattributes
$ git add .
$ git commit -m "previous state"
$ rm -rf .git/lfs/objects/
如果没有陶瓷解决方案,我可以接受低级(管道)命令。
如果有人想知道如何使用 Git LFS 保存文件,FILENAME
以以下格式提交。
version https://git-lfs.github.com/spec/v1
oid sha256:$(sha256sum $FILENAME | awk '{print ;}')
size $(du -b $FILENAME | awk '{print ;}')
移动 .git
文件夹后,文件在 git status
中显示已修改,据我所知,解决此问题的唯一方法是调用 git add .
,这会更新git 索引文件。 Git 如果文件被修改时目标文件丢失,LFS 会重新创建目标文件,因此不幸的是,下面的解决方案与使用问题中的命令没有什么不同 除了 这是多线程的。在 Windows,建议关闭实时保护以避免 CPU 反恶意软件服务可执行文件的高使用率。
#!/bin/bash
set -e
task() {
REPO=""
FILE=""
BASE=$(cd $REPO; pwd)
FILEPATH="$BASE/$FILE"
SHA=$(sha256sum "$FILEPATH" | awk '{print ;}')
SIZE=$(du -b "$FILEPATH" | awk '{print ;}')
NEWFILE="$BASE.git/$FILE"
cat > "$NEWFILE" <<-EOF
version https://git-lfs.github.com/spec/v1
oid sha256:$SHA
size $SIZE
EOF
echo " Wrote out $FILE"
}
if [[ $# -ne 1 ]]
then
echo "Please provide the path"
exit 2
fi
REPO=""
GITFILES=($(find "$REPO" -name ".git*" -exec basename {} \;))
if [[ ${#GITFILES[@]} -ne 0 ]]
then
echo "The path contains .git files. Aborting..."
echo "Path: $REPO"
for GITFILE in "${GITFILES[@]}"
do echo " $GITFILE"
done
exit 2
fi
FILES=($(find "$REPO" -type f -exec basename {} \;))
echo "Found ${#FILES[@]} files"
N=$(nproc --all)
echo "Number of threads: $N"
BASE=$(cd $REPO; pwd)
echo "Creating directory $BASE.git"
mkdir "$BASE.git"
for FILE in "${FILES[@]}"
do
(i=i%N); ((i++==0)) && wait
task "$REPO" "$FILE" &
done
wait
WRITTEN=($(find "$BASE.git" -type f -exec basename {} \;))
if [[ ${#WRITTEN[@]} -ne ${#FILES[@]} ]]
then
echo "${#WRITTEN[@]} out of ${#FILES[@]} files are written. Aborting..."
exit 2
fi
echo "All files written"
echo "Committing the previous state"
cd "$BASE.git"
git init
git add .
git commit -m "previous state"
echo "Using Git LFS to track these files"
git lfs install
git lfs track "*"
echo ".gitattributes filter= diff= merge= text" >> .gitattributes
git add .
git commit -m "git lfs track all files"
echo "Moving .git to $REPO"
cp -r "$BASE.git/.git/" "$BASE/.git/"
cp "$BASE.git/.gitattributes" "$BASE/.gitattributes"
cd "$BASE"
git add $(git status --porcelain | awk '{print $NF;}')
echo "Erasing temporary folder $BASE.git"
rm -rf "$BASE.git"
echo DONE
我有一个包含大量二进制文件的文件夹。我想 保存 当前状态,进行一些更改并查看 git status
更改了哪些文件。我认为使用 Git LFS 是个好主意,因为它只为每个文件保留 3 行大小和哈希信息。
问题是 git add .
命令需要很多时间并进行备份。是否可以只提交指针文件而不创建 LFS 对象?
我使用的命令:
$ git init
$ git lfs install
$ git lfs track "*"
$ echo ".gitattributes filter= diff= merge= text" >> .gitattributes
$ git add .
$ git commit -m "previous state"
$ rm -rf .git/lfs/objects/
如果没有陶瓷解决方案,我可以接受低级(管道)命令。
如果有人想知道如何使用 Git LFS 保存文件,FILENAME
以以下格式提交。
version https://git-lfs.github.com/spec/v1
oid sha256:$(sha256sum $FILENAME | awk '{print ;}')
size $(du -b $FILENAME | awk '{print ;}')
移动 .git
文件夹后,文件在 git status
中显示已修改,据我所知,解决此问题的唯一方法是调用 git add .
,这会更新git 索引文件。 Git 如果文件被修改时目标文件丢失,LFS 会重新创建目标文件,因此不幸的是,下面的解决方案与使用问题中的命令没有什么不同 除了 这是多线程的。在 Windows,建议关闭实时保护以避免 CPU 反恶意软件服务可执行文件的高使用率。
#!/bin/bash
set -e
task() {
REPO=""
FILE=""
BASE=$(cd $REPO; pwd)
FILEPATH="$BASE/$FILE"
SHA=$(sha256sum "$FILEPATH" | awk '{print ;}')
SIZE=$(du -b "$FILEPATH" | awk '{print ;}')
NEWFILE="$BASE.git/$FILE"
cat > "$NEWFILE" <<-EOF
version https://git-lfs.github.com/spec/v1
oid sha256:$SHA
size $SIZE
EOF
echo " Wrote out $FILE"
}
if [[ $# -ne 1 ]]
then
echo "Please provide the path"
exit 2
fi
REPO=""
GITFILES=($(find "$REPO" -name ".git*" -exec basename {} \;))
if [[ ${#GITFILES[@]} -ne 0 ]]
then
echo "The path contains .git files. Aborting..."
echo "Path: $REPO"
for GITFILE in "${GITFILES[@]}"
do echo " $GITFILE"
done
exit 2
fi
FILES=($(find "$REPO" -type f -exec basename {} \;))
echo "Found ${#FILES[@]} files"
N=$(nproc --all)
echo "Number of threads: $N"
BASE=$(cd $REPO; pwd)
echo "Creating directory $BASE.git"
mkdir "$BASE.git"
for FILE in "${FILES[@]}"
do
(i=i%N); ((i++==0)) && wait
task "$REPO" "$FILE" &
done
wait
WRITTEN=($(find "$BASE.git" -type f -exec basename {} \;))
if [[ ${#WRITTEN[@]} -ne ${#FILES[@]} ]]
then
echo "${#WRITTEN[@]} out of ${#FILES[@]} files are written. Aborting..."
exit 2
fi
echo "All files written"
echo "Committing the previous state"
cd "$BASE.git"
git init
git add .
git commit -m "previous state"
echo "Using Git LFS to track these files"
git lfs install
git lfs track "*"
echo ".gitattributes filter= diff= merge= text" >> .gitattributes
git add .
git commit -m "git lfs track all files"
echo "Moving .git to $REPO"
cp -r "$BASE.git/.git/" "$BASE/.git/"
cp "$BASE.git/.gitattributes" "$BASE/.gitattributes"
cd "$BASE"
git add $(git status --porcelain | awk '{print $NF;}')
echo "Erasing temporary folder $BASE.git"
rm -rf "$BASE.git"
echo DONE