Skip to content

Instantly share code, notes, and snippets.

@simonw
Created August 23, 2023 01:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save simonw/2a866f0c54462d6cdd95b97cd9c3ffa3 to your computer and use it in GitHub Desktop.
Save simonw/2a866f0c54462d6cdd95b97cd9c3ffa3 to your computer and use it in GitHub Desktop.
Script for reviewing every change to every file in a current Git repo and rejecting or keeping it
#!/bin/bash
# Get the list of changed files
files=$(git diff --name-only)
# Loop through each changed file
for file in $files; do
# Show the diff of the file
git diff $file
# Ask the user if they want to abandon the change
read -p "Abandon this change? y/n: " response
if [ "$response" = "y" ]; then
git checkout -- "$file"
echo "Changes in $file abandoned."
fi
done
@simonw
Copy link
Author

simonw commented Aug 23, 2023

Generated here https://chat.openai.com/share/3b0bab2f-0979-4b1d-9a1f-228d2738cec6

Prompt:

Write me a bash script that does the following:

Identify which file paths have changed using git diff

Loop through each one, and for each one display the diff of just that file and ask "Abandon this change? y/n"

If the user says y, use "git checkout filepath" to abandon the changes. Otherwise do nothing

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