git patch

Useful commands:

git format-patch master --stdout > fix_empty_poster.patch
git apply --stat fix_empty_poster.patch
git apply --check fix_empty_poster.patch
git am --signoff < fix_empty_poster.patch
git apply --reject --whitespace=fix fix_empty_poster.patch

Git merge several repos

There are many ways to do it.

One way is:

– Clone old-repo1 to local machine

– Move everything to old-repo1/old-repo1

– Go to new directory

– Git remote add old-repo1 ../old-repo1

– Git pull old-repo1 master


There is always a hard step. I use the following script to move old files to its sub directory

for file in $(find . -maxdepth 1 -type d -not -name '.*'); do git mv $file $(echo $file | sed -e 's/^/sub_dir\//'); done

for file in $(find . -maxdepth 1 -type f); do git mv $file $(echo $file | sed -e 's/^/sub_dir\//'); done


How to remove API keys from git history

The last step before making our repo public is to delete all the API secrete keys from the file and from the git history.

git rm backend/config/environments.js

git add .
git commit

git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch backend/config/environments.js' --prune-empty --tag-name-filter cat -- --all

git push origin master --force

Now, you have removed the old file and all the history associated with it. Now add the new file, and commit as regular.


Day 4, data structures 2

There are two sprints for data structures, with two days per sprint. My pair and I finished the first data structure sprint yesterday and started to work on the second data structure sprint today. We implemented LinkedList, Tree and Set today.

One thing that really slowed us down was debugging the contains function for Tree. Because the contains function needs to search recursively, the function was written as a recursive search. However, when we passed the result around as a parameter of the function, we override results from our previous round. This creates enormous confusion and it takes us a good two hours to find the bug. I swear that from now on, when possible, I will try to avoid pass results in recursive function. Using a global variable is less clean, but much easier to read and debug.

Something important for today:

– Testing. During testing, only test the interface, and nothing else.

– Coding convention about capitalized function names. A capitalized function is supposed to be run with the new key word. For example, we should run: new Tree() or makeTree().

– Constructors in JS is only referred to the psedoclassical style(?) maker function.


Yes. There are so much to learn about Git such that we could have a lecture for it everyday. Marcus did a fantastic job today on Git and my understanding is getting much better.

First, I realized that pull request is a GitHub feature, not a Git feature.

Second, I realized that SHA is the unique ID associated with each state, and all the other stuff (branch names, tag names, HEAD) are variable names referring to SHA. As long as I accept the fact that Git will point those variable names to different SHA automatically in the background, life is not that complicated.

Third, HEAD is almost the same as the “you are here” star in the maps.

Fourth, I am guessing that the difference between fast-forward merge and none-fast-forward merge is whether a new SHA has been created or not, but I am not 100% sure.