Skip to content

Instantly share code, notes, and snippets.

@basiclines
Created January 23, 2013 17:27
Show Gist options
  • Save basiclines/4610591 to your computer and use it in GitHub Desktop.
Save basiclines/4610591 to your computer and use it in GitHub Desktop.
Used for automatically choose remote images files for resolving conflicts in Git and keeps logs of all that images changes
# Script used for automatically choose remote images files for resolving conflicts in Git
# You need your working copy to be in merging status
# Define main folders
LOG_FOLDER="git_log/"
STATUS_FILE=$LOG_FOLDER"raw_status.txt";
BOTH_FILE=$LOG_FOLDER"both_modified.txt";
THEIRS_FILE=$LOG_FOLDER"theirs_modified.txt";
THEIRS_NEWFILE=$LOG_FOLDER"theirs_new.txt";
THEIRS_DELETIONSFILE=$LOG_FOLDER"theirs_deleted.txt";
# Clean logs
rm -rf $LOG_FOLDER
# Prepare logs
mkdir $LOG_FOLDER
# Get status
git status >> $STATUS_FILE
# Start filtering
cat $STATUS_FILE | while read line
do
if [[ "$line" == *".png"* || "$line" == *".gif"* || "$line" == *".jpg"* ]]
then
# Modified ones
if [[ "$line" == *"modified"* ]]
then
if [[ "$line" == *"both modified"* ]]
then
# Ours
echo $line | sed 's/# both modified: //' >> $BOTH_FILE
else
# Theirs
echo $line | sed 's/# modified: //' >> $THEIRS_FILE
fi
fi
# New ones
if [[ "$line" == *"new file"* ]]
then
echo $line | sed 's/# new file: //' >> $THEIRS_NEWFILE
fi
# Deleted ones
if [[ "$line" == *"deleted"* ]]
then
if [[ "$line" == *"deleted by them"* ]]
then
# Theirs (with conflict)
echo $line | sed 's/# deleted by them: //' >> $THEIRS_DELETIONSFILE
else
# Theirs
echo $line | sed 's/# deleted: //' >> $THEIRS_DELETIONSFILE
fi
fi
fi
done
# Start resolving (choosing theirs)
cat $BOTH_FILE | while read line
do
git checkout --theirs -- $line
git add $line
done
# Start resolving removed ones
cat $THEIRS_DELETIONSFILE | while read line
do
git rm $line
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment