Removing Dropbox Conflicted Files Using Git

I have a Mac Mini at work and a MacBook Pro that I often do my coding work in. My coding folder is on a Dropbox folder - this folder gets synced between the 2 computers.

You might ask - why don’t just use git to sync the code? Yes, I could, in fact that is my usual workflow - the only problem is when I forgot to push my changes and then I left without my latest work. With Dropbox folder all my work shared to the cloud automatically - which very nice as a backup plan.

One minor annoyance with this setup is the occasional file conflicts.

This is what it looks like:

➜  git:(2-way-binding-service) ✗ git status
# On branch 2-way-binding-service
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#     flex/forms/CommentsForm (HOPE's conflicted copy 2012-05-25).mxml
#     flex/forms/ServiceForm (HOPE's conflicted copy 2012-05-25).mxml

Most of the time, I don’t really care about the conflicted files and I can just easily discard them. The easiest way to do that I found is by using git stash:

git add --all && git stash save && git stash pop

Let me break it down:

  • git add –all - tells git to stage everything even untracked files
  • git stash save - saves it to your stash list
  • git stash drop - tells git to drop the most recent stash entry

Another way would be to create a shell script to do so - I came up with this convoluted script:

git status | grep conflicted | awk -F '#' '{print "\""$2"\""}'|tr -d '\011'|xargs rm

The awk part is enclosing the file path with doubel quotes, for example:

"     flex/forms/ServiceForm (HOPE's conflicted copy 2012-05-25).mxml"

The tr command removes the tab just before the filename.

Git stashing seems to be a winner here - it’s very simple and easy to understand. Only works with directory under git though.