All My Brain Where stuff from my brain lands

June 2, 2012

git diff with color words

Filed under: Programming — Tags: , , , — Dennis @ 7:10 am

I had these files with very very long lines of text on each line. It was paragraphs worth of words but not word wrapped. These files were stored in a git repository. Now and then, someone would change a word. Diff with line based output was difficult to find what actually changed.

I figured there must be a way to see just the words. A little searching around the docs and I found it.

> git diff --word-diff=color

Perfect. I still got ling scrolling lines though. You can override that with your $GIT_PAGER variable or I just piped the output manually for a one time fix:

> git diff --word-diff=color | less -r

Much easier to see the changes!

December 7, 2011

How to fix that mistake commit you just pushed to your git repository

Filed under: Programming — Tags: , , , — Dennis @ 12:51 pm

I’ve already written a time or two how you can use git rebase to change your commit history as you work. Handy handy.. I think everyone should know how to do that.

Next up.. what if you pushed a commit and realize it’s not so great. First of all, everyone discourages this of course. The encouraged way is to just make another commit that fixes what you want different. We all want to break that rule every now and then though. Here’s how…
(more…)

November 11, 2011

Git Rebasing Tips

Filed under: Software — Tags: , , , — Dennis @ 1:53 pm

So there you are, using git to store, track and share your code with a few others. Maybe many others. You make a change, someone else makes a change, one or the other of you pulls the others changes and BAM.. you get that merge commit. It really isn’t harmful of course, but it cleans up your repository a lot to get rid of them. So…

  1. When you pull, use –rebase.
    git pull --rebase
    

    There. It did it for you. All your commits go after the commits on the remote origin.

  2. You forgot to do that. No prob…
    git pull # oh man.. I forgot.. merge commit
    git rebase origin/master # There.  Pretty easy isn't it.
    

So of course, you might have the same issue if you were working on a branch. You check out master, make some commits, go back to your branch, make some more, etc. It works the same way.

# on your branch
git rebase master

There. You can pull in the master branch changes but put all your branch changes after so you don’t have to have the merge commit again.

So you wrote that branch, changed master, and then you merge your branch back to master and get a merge commit again. In this case there isn’t a ref to rebase off of so intuitively like remote/origin or master. No prob, just use gitk or git log or whatever to find out what the sha1 of the old master was before you made your merge.

git rebase 

There. No merge commit again.

Now, there are a bunch of more advanced things rebase can do. You can use it to edit commits that weren’t quite right. You can also change the order of commits, edit the commit message, drop commits completely, and other cool things. You can do it all interactively too…

git rebase -i  # fun for all!

I leave you to study that part on your own.

March 8, 2010

YUI Image Uploader gets a code repository

Filed under: Software — Tags: , , , , , , , — Dennis @ 7:45 am

I’ve created a github project for the YUI Image Uploader.

You can download the scripts and example page here:
http://github.com/mulicheng/yuiupload

This will also facilitate user contributed changes and backend scripts.

December 2, 2009

git logk

Filed under: Programming — Tags: , , , , — Dennis @ 4:37 pm

Do you like gitk? I find it almost invaluable in merging, branching, looking at old revisions, diffs, etc. I find it annoying that git log is hard to glean the same information. I searched a round a bit and found that git log is quite configurable as to what it outputs. Here is a simple alias that outputs the log with some of the data you’d find by viewing gitk.

git config alias.logk 'log --graph --pretty=format:"%h %ae: %s" --decorate --abbrev-commit'

You can add –global so you don’t have to make a logk alias for every repository.
You can also read the man page for “git log” and change the format to suite your liking.

November 17, 2009

Dual Master Git Repositories

Filed under: Programming — Tags: , , — Dennis @ 10:23 am

One of the nice things about git, is the ability to work in a distributed manor. Instead of having to have a central repository for your source code, you can create a copy of your repository and do work, while sharing the changes, on any number of machines. Often, when a few developers share code, they still use git with a central repository. There isn’t anything wrong with this, but sometimes, I find myself wanting to set something like this when I only want to share code between a couple computers where I am the only developer. In this case, I don’t need 3 copies of the code. I want to be able to push or pull changes between each of the machines without having to push to a 3rd repository.

So, you might try the following steps:

# on the 1st machine
> git init .
> # make some code changes
> git add ...
> git commit
# 2nd machine
> git clone <1st machine ref>
> # make some changes
> git commit
> git push # here is the problem

When you push from the 2nd machine to the 1st, the HEAD on the 1st machine is updated. The problem is that your working copy is NOT updated. To fix this, there are two solutions.

Mediocre, recover from doing the push solution:

# warning, the following will destroy any local changes you had made.
> git reset --hard HEAD

If you had made changes on the 1st machine and forgot to commit them, you’d need to stash them, check out to a branch, or whatever.

Better way, avoid the reset all together

# on the 2nd machine
> git push origin master:refs/heads/tmp_branch_name
# on the 1st machine
> git merge tmp_branch_name
> git branch -d tmp_branch_name

Another solution would be to add a remote on the 1st machine that points to the 2nd machine. Then each machine can just pull from the other rather than doing any pushes at all.
Have fun.

Older Posts »

Powered by WordPress

css.php
%d bloggers like this: