Thursday, November 29, 2012

my personal git guide

To mark a file such that you always get its latest versip when you do git pull, but your changes are never comitted or pushed or shown in the diff:
git update-index --assume-unchanged /path/to/file
And to undo the last step:
git update-index --no-assume-unchaged /path/to/file

When you've made a commit in the detached head state

git checkout -b temp-branch-name
git merge
git branch -d temp-branch-name
git push origin master

Stashing

git stash save "Working on so and so. | 70% complete."
git stash list
git pull
git stash apply
Then resolve any conflicts in the reported files, and do
git add
to mark they're resolved. git stash apply applies the last stash by default; if you want to apply any earlier stash do:
got stash apply stash@{3}
Stashes are ordered such that stash@{0} is the latest, stash@{1} is the one before that ans so on. You can delete the stashes with:
git stash drop stash@{0}

To revert to an older commit.

Coming soon!

Wednesday, November 28, 2012

git what changed

So, let's see you just did a git pull, and you have a feeling the last few (let's say 4) commits are by a coupla not-so-bright people, and you want to take a look at the code added by them, commit by commit, file by file. One way would have been to just take the diff between HEAD and HEAD^^^^, but that it will only show you the net change, so what you can do is is this:
git whatchanged -p -4 --pretty=full
By the way, doing the following would get the same output as well:
git log -p4
Also, my boss asked me to come up with a way to find the commit history of just one file. I said, git would provide a functionality right away, let me look. He said no, don't 'waste' time on it. Well, here it is. I just stumbled upon it while fiddling with git log.
git log -p -4 /path/to/file
And if you wanna see the history of a Deleted file...
git log --follow -- /path/to/file
Needless to say, this can only be done for one file.

Sunday, November 11, 2012

Which linux version?

So you're using a linux version on some friend's machine. Or you have just logged in to a remote machine, and your curiosity isn't letting you do the simple cp command you went there to run, and you have to know the flavor and the release of the linux installed. Here's how you do it:
You run this:
cat /etc/*-release