Tags: ,

Git

Here are some things that I find useful in git. Basically this is my scratch pad of commands I need.

Awesome Cheat Sheet

Replacing one branch with another.

To set master to be equal to ‘tweaks’

git checkout tweaks
git merge -s ours master
git checkout master
git merge tweaks

Merging

Stop your local file and accept theirs (or vice versa).

git checkout --ours filename.c
git checkout --theirs filename.c

Undo the last commit (before you push)

git reset --soft HEAD^

Clearing out the working dir:

git clean -d -x -n  # removes all untracked and ignored files, change "-n" to "-f" to actually perform it

Now something XCode Clear out all the cruft.

~/Library/Developer/Xcode/DerivedData

Reverting a commit (actually reverting it, i.e. a new commit with the reverse merge)

git revert

Splitting off a branch at a given commit, and rolling the origin branch back to that same commit

git checkout core
git branch core-experimental
git reset --hard <SHA of last commit you want to keep>
git push -f <remote> core

Getting the SHA of the submodule of a tag

$ git ls-tree released-1.2.3 foo

Stashing just certain changes

Add all the files you don’t want to stash, then:

$ git stash --keep-index

Then unstage your changes if you didn’t really want to stage them with:

$ git reset --soft

Deleting a file from the index without deleting the local copy

git rm --cached filename

Getting diffing your changes before you push them:

git diff origin/master

Diffing the index before commit

git diff --cached

Tracking all remote branches

for remote in `git branch -r | grep -v master `; do git checkout --track $remote ; done

Leave a Reply

Your email address will not be published. Required fields are marked *