Skip to content

Instantly share code, notes, and snippets.

@gubatron
Last active September 26, 2024 15:26
Show Gist options
  • Save gubatron/6ebbb7e3326e08350447451db288c759 to your computer and use it in GitHub Desktop.
Save gubatron/6ebbb7e3326e08350447451db288c759 to your computer and use it in GitHub Desktop.
split_huge_diff.sh
split_file() {
local file="$1"
if [[ ! -f "$file" ]]; then
echo "File '$file' does not exist."
return 1
fi
# Use short options compatible with your version of split
split -b 50k -a 2 "$file" "${file}.part"
# Rename the split files to have numeric suffixes starting from 1
i=1
for f in "${file}.part"*
do
mv "$f" "${file}.part${i}"
i=$((i+1))
done
}
rm 2.0.patch*
# gets a patch excluding binary files, auto generated .cpp files and auto generated java files otherwise the patch is too big
git diff --diff-filter=d --binary 240fceb14a2496573b15d813ea40ca0cf9b71489 HEAD -- ':(exclude)src/main/java/com/frostwire/jlibtorrent/swig/' ':(exclude)swig/libtorrent_jni.cpp' ':(exclude)*.jar' ':(exclude)*.zip' ':(exclude)*.md' ':(exclude)*.txt' > 2.0.patch
# splits it in chunks of 50kb so we can paste it one at the time to chatGPT
split_file 2.0.patch
ls -lth 2.0.patch*
@gubatron
Copy link
Author

MBP14inchDec2021:frostwire-jlibtorrent gubatron$ ./split_huge_diff.sh 
-rw-r--r--  1 gubatron  staff    26K Sep 26 09:26 2.0.patch.part9
-rw-r--r--  1 gubatron  staff    50K Sep 26 09:26 2.0.patch.part8
-rw-r--r--  1 gubatron  staff    50K Sep 26 09:26 2.0.patch.part7
-rw-r--r--  1 gubatron  staff    50K Sep 26 09:26 2.0.patch.part6
-rw-r--r--  1 gubatron  staff    50K Sep 26 09:26 2.0.patch.part5
-rw-r--r--  1 gubatron  staff    50K Sep 26 09:26 2.0.patch.part4
-rw-r--r--  1 gubatron  staff    50K Sep 26 09:26 2.0.patch.part3
-rw-r--r--  1 gubatron  staff    50K Sep 26 09:26 2.0.patch.part2
-rw-r--r--  1 gubatron  staff    50K Sep 26 09:26 2.0.patch.part1
-rw-r--r--  1 gubatron  staff   426K Sep 26 09:26 2.0.patch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment