Skip to content

Instantly share code, notes, and snippets.

@aldoyh
Created April 25, 2024 21:46
Show Gist options
  • Save aldoyh/94596908f9d85722a436d2bf1cbb57d3 to your computer and use it in GitHub Desktop.
Save aldoyh/94596908f9d85722a436d2bf1cbb57d3 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Clone the original repo
git clone https://github.com/mohammadrz003/moonfo-youtube.git moonfo-youtube-original || {
echo "Error cloning repository. Exiting."
exit 1
}
# Navigate to the cloned repo
cd moonfo-youtube-original || {
echo "Error changing directory. Exiting."
rm -rf moonfo-youtube-original
exit 1
}
# Initialize an empty commit history
git reset --hard HEAD || {
echo "Error resetting repository. Exiting."
rm -rf moonfo-youtube-original
exit 1
}
git clean -df || {
echo "Error cleaning up untracked files. Exiting."
rm -rf moonfo-youtube-original
exit 1
}
# Apply each commit in reverse order
for i in $(git log -1 --reverse); do
COMMIT_HASH=$(git rev-parse $i) || {
echo "Error getting commit hash. Exiting."
rm -rf moonfo-youtube-original
exit 1
}
COMMIT_MESSAGE=$(git show -s --format=%B $i) || {
echo "Error getting commit message. Exiting."
rm -rf moonfo-youtube-original
exit 1
}
# Apply the commit changes
git reset --hard $COMMIT_HASH || {
echo "Error resetting repository to previous state. Exiting."
rm -rf moonfo-youtube-original
exit 1
}
git apply <(git diff-tree -p $COMMIT_HASH HEAD) || {
echo "Error applying commit changes. Exiting."
rm -rf moonfo-youtube-original
exit 1
}
# Print the commit message
echo "$COMMIT_MESSAGE"
done
# Remove the original repo and exit
rm -rf moonfo-youtube-original
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment