A situation I encounter frequently is one where Unity has made local changes and I need to do a git pull. One or more of the local changes will get overwritten, blocking the merge. I don’t particularly care about this file as I didn’t manually edit it and I just need to get the latest code.

I don’t care about this file, but it’s blocking my git pull.

I don’t care about this file, but it’s blocking my git pull.

Here’s how you can git pull, but discard any local changes that might conflict: https://gist.github.com/kelnishi/7e4973abdef2c55b768f6e61cbc7639f

First, use stash --include-untracked to set aside all local changes.

git stash --include-untracked

Now when you pull, it should finish cleanly.

git pull

Next you’ll stash pop to reapply all the local changes you had. After doing this, the files that blocked the original pull will be marked as conflicted.

git stash pop

*Make sure you’re at the root directory of your git repo.

We’ll use some bash git magic to list all the files.

ls-files -u will list all unmerged (conflicted) files from the stash pop.

The output will be a bit verbose so we’ll use cut to select just the file names.

Since each conflict has multiple states listed, we’ll use uniq to remove the duplicate entries.

awk will wrap our lines in quotes so spaces won’t trip us up.

paste will concatenate our 1 file per line into a single space delimited line.

git ls-files --full-name -u | cut -f 2 | uniq | awk '{print "\""$0"\""}' | paste -s -d" " -

You should get all the conflicted files, wrapped in quotes, on a single line output.

*Now is a good time to check to see that you’re not blowing away work you want to keep.

If it all the files are ones you think should be reset, we’re good to go.

Next, FILES=$(!!) saves the output of the last command into a variable. We need to do this because reset will change state and the output of ls-files.

eval will unwrap our variable and allow us to pass the space delimited list as parameters to our two git commands. In this case, we’ll use reset (to unstage and de-conflict) and checkout (to discard the changes) against all our conflicted files.

FILES=$(!!); eval git reset -- $FILES; eval git checkout -- $FILES

After running the last line, you should be in a state similar to before you started this whole process. You should have your local changes intact (and not staged), your branch up-to-date with origin, and any conflicts blocking the merge will have been discarded.

the gist: https://gist.github.com/kelnishi/7e4973abdef2c55b768f6e61cbc7639f

AuthorKelvin Nishikawa

Using homebrew to install python3 on macOS Mojave required a little bit of permissions juggling.

sudo install -d -o $(whoami) -g admin /usr/local/Frameworks
brew link python

via this gist

AuthorKelvin Nishikawa

Recently, I’ve had to juggle multiple copies of a git repo because reasons. This has inevitably led to me accidentally running commands in the terminal in the wrong copy. So, to avoid this, I’ve written a bash profile script that will set my terminal windows to different colors based on the present working directory.

Here: https://gist.github.com/kelnishi/c522a97b43ea42bc50b07b25bf824a0d

To use it, just stick it into your .bash_profile, then

Screen Shot 2019-07-22 at 1.11.07 PM.png

In whatever directory you want to color

Screen Shot 2019-07-22 at 1.12.46 PM.png

> dircolor “Some Terminal.app color profile


This will place a .window_color turd in that directory.

Screen Shot 2019-07-22 at 1.13.10 PM.png

Now, whenever you are under that directory, the window color will change.

You can rm .window_color to remove the turd if you no longer want to color the directory.

AuthorKelvin Nishikawa