Member of the EVE Tweet Fleet
Jan 24

A Second Blog? Using GIT and Python? Yes

By Xeross Posted in Blog News Comments (4)

What started out as an experiment with GIT and Python ended up being something I’ll probably keep.

The beauty of this new blog is that it’s really easy for me to write new posts, as with WordPress I need to login, hit Add New, fill in all the fields and hit publish. However with the new one I can just type in:

python ../post.py Some Title Here

It will chuck out a template with the title and date filled in, and open it in vim (Or any other editor, can be modified), after that I just write down what I want, save the file and exit the editor, and it will automatically be uploaded to the blog.

This is all done through the GIT Source Code Management system, although it is now more of a Content Management System in this case, it will save the posts in a specified location in the repository and as soon as it hits the server a python script will run that will chuck out static html with all the posts and css and w/e.

I’ll probably post more on http://blog.xeross.nl/ (Has been taken offline) and keep this more EVE focused.

Regards, Xeros

Tagged with:
Oct 12

GIT: Change revision author’s email/name

By Xeross Posted in How-To's, Tech, Version Control Comments (7)

So recently I dived a little deeper into GIT, the best version control system in my opinion. however after making a few commits to a repository I created (For some modification to a program’s source code) I noticed it didn’t have my name on it as the author, and after 1 failed attempt of setting the name/email the their values of commits after that were even worse.

So I needed a way to change the author’s name and email on the commits, after searching a little using google I encountered this page on GitHub, however I’ve decided to write a tutorial on it anyways, we’ll use the code from GitHub though.

Ok to do this we are going to use a bash script (which is basically a  list of commands to execute) they’re work on linux and also on windows if you have msysgit. here’s the code.

git filter-branch --env-filter '

an="$GIT_AUTHOR_NAME"
am="$GIT_AUTHOR_EMAIL"
cn="$GIT_COMMITTER_NAME"
cm="$GIT_COMMITTER_EMAIL"

if [ "$GIT_COMMITTER_EMAIL" = "EMAIL_OF_COMMITER_HERE" ]
then
    cn="NEW_NAME_COMMITER"
    cm="NEW_EMAIL_COMMITER"
fi
if [ "$GIT_AUTHOR_EMAIL" = "EMAIL_OF_AUTHOR_HERE" ]
then
    an="NEW_NAME_AUTHOR"
    am="NEW_EMAIL_AUTHOR"
fi

export GIT_AUTHOR_NAME="$an"
export GIT_AUTHOR_EMAIL="$am"
export GIT_COMMITTER_NAME="$cn"
export GIT_COMMITTER_EMAIL="$cm"
'

As you can see this code uses the git filter-branch command, and everything on line 2-22 is basically the filter code. Now to replace a certain commiter or author just replace EMAIL_OF_AUTHOR/COMMITER_HERE with the email of that committer/author, and replace NEW_NAME_COMMITER/AUTHOR and NEW_EMAIL_COMMITER/AUTHOR with the new email and name you want him/her to have. You can replace multiple commiters/authors by copy-pasting the if blocks (See below for that part)

if [ "$GIT_COMMITTER_EMAIL" = "EMAIL_OF_COMMITER_HERE" ]
then
    cn="NEW_NAME_COMMITER"
    cm="NEW_EMAIL_COMMITER"
fi
if [ "$GIT_AUTHOR_EMAIL" = "EMAIL_OF_AUTHOR_HERE" ]
then
    an="NEW_NAME_AUTHOR"
    am="NEW_EMAIL_AUTHOR"
fi

You can duplicate these for as many authors/commiters you want to replace. now after you finished this document save it somewhere you can access it easily (From the command line/console), and after that go inside your git repository’s folder (Ofcourse also on the command line aka console), when in there type the following.

sh /path/to/previous/saved/script.ext

When you’ve done that a progress counter will start to run, this is the git filter-branch scanning through all your commits. After this process finishes your repo will be updated with the new name/email (use “git log” to check), now to push it to a remote repository push like normal but instead of “git push” use “git push -f”, after this is done your remote repo is also updated.

Well that’s it, hope it was useful and if you have any questions or remarks don’t hesitate to post a comment ;)

Regards, Xeross

Tagged with: