Posterous theme by Cory Watilo

Filed under: git

Edit a few previous commits

Working in feature branch I put wrong issue number to commit message. In fact, I did it not with last commit, but with a two or three in a row.

If this is just a last commit you could easily use git commit --amend.

Finally I found solution on stackoverflow. I’ll quote it here:

If the commit you want to fix isn’t the most recent one:

git rebase --interactive $parent_of_flawed_commit

If you want to fix several flawed commits, pass the parent of the oldest one of them.

An editor will come up, with a list of all commits since the one you gave.

Change pick to reword (or on old versions of Git, to edit) in front of any commits you want to fix. Once you save, git will replay the listed commits.

Git will drop back you into your editor for every commit you said you want to reword, and into the shell for every commit you wanted to edit. If you’re in the shell:

Change the commit in any way you like.

git commit --amend
git rebase --continue

Most of this sequence will be explained to you by the output of the various commands as you go. It’s very easy, you don’t need to memorize it – just remember that git rebase —interactive lets you correct commits no matter how long ago they were.

git, gitosis, tailor, and bzr

git

До общения с Oleganza я не видел у git каких-либо ярких преимуществ перед bzr. И, наверное, не увидел бы, если бы не Олег. Первое что было самым необычным - git полностью децентрализованый. И привычный svn-like workflow тут не работает. Надо было привыкать к branch-style. Второе - это то, что команды с теми же названиями что и у svn имеют другой смысл. Жутко понравилось что ветки git держит в себе, то есть не надо плодить по 3-4 папки для разных фичей.

gitosis

Также я задумался о совместной работе. github - это, конечно, хорошо, но у меня уже есть багтракер понимающий git. Отчего бы не попробовать git на своем сервере? Был заведен юзерь git без пароля [cc lang="bash"] sudo adduser --shell /bin/sh --gecos 'git version control' --disabled-password --home /home/git git [/cc] поставлен gitosis [cc lang="bash"] sudo apt-get install gitosis [/cc] сделаны небольшие правки его сорсов (дело в том, что по умолчанию gitosis создает репо с маской 0750, мне же надо было с 0755 - чтоб www-data мог его читать): правим [cc lang="bash"] /var/lib/python-support/python2.5/gitosis-0.2-py2.5.egg/gitosis/repository.py [/cc] и заменяем 0750 на 0755. Подробнее описано в блоге разработчика gitosis.

tailor and bzr

Когда все взлетело с git, решил попробовать отконвертировать при помощи утилиты tailor старые репо из bzr в git. Конфиг получился примерно такой (замечания приветствуются): [cc lang="ini"] [DEFAULT] verbose = True [project] target = git:target start-revision = INITIAL root-directory = /home/dm/tmp/bzr2git state-file = tailor.state source = bzr:source subdir = bzr2git.tmp [bzr:source] repository = /home/dm/bzr/BZR_PROJECT_HERE [git:target] repository = /home/dm/tmp/bzr2git/tmp/.git [/cc] и после запуска [cc lang="bash"] tailor bzr2git.conf [/cc] в /home/dm/tmp/bzr2git/bzr2git.tmp появляется вполне живой git-репозитарий. Его я уже стягивал к себе и вливал в gitosis от себя.

Примечание

git не отслеживает пустые папки, и в процессе конвертации теряются "log", "tmp", etc... Чтоб отслеживал достаточно [cc lang="bash"] mkdir log touch log/.empty [/cc]