As of 2016-02-26, there will be no more posts for this blog. s/blog/pba/
Showing posts with label Git. Show all posts

This is a note page for Git usage that I most likely cant remember how to issue the commands for the tasks.

1   Manipulating commit history

1.1   Inserting a commit

This shows how to insert one in the past:

% git checkout -b new-commit after-this-commit-in-master-branch
% # doing stuff for the new commit
% git commit
% git rebase new-commit master

1.2   hg revert

% git reset --hard

I believe the title says it all about this blog post.

I love --amend, but sometimes, well, most of times, the commit message is just the same, there is no need to edit it. We are just forgetting to add files or simply fix some typos.

I found out how to keep the message via tab-completion, then I was disappointed, because you have to use --no-edit, no shortened option now for use. I was hoping something like -M.

For me, let Git bring up editor and save and quit is the faster way, but still good to know this option. As for Mercurial (Hg), it has --amend, but no equivalent --no-edit.

gitfiti, an interesting idea to paint graffiti on GitHubs commit history calendar, though it probably doesnt have much practical value beside becacuse its fun and I can do it!

Anyway, I wasnt going to write about it because I didnt want to create repositories just for fun. But I remembered my vcsstat.sh project, and if you combine both, you can have:

https://lh5.googleusercontent.com/-LBxEscGbTKM/UZuNioCbXSI/AAAAAAAAE0I/6vumCkRuOv4/s800/gitfiti%2520and%2520vcsstat.sh%25202013-05-21--23%253A00%253A22.png

The creation of gitfiti wasnt quite clear when I started. There were five repositories in the screenshot. I used five because its easier if I messed up with week offset, I could just delete a repository and recreate with correct week offset. Anyway, with vcsstat.sh, two extra modes.

There seemed to be some calculation issue with vcsstat.sh, some days colors are off, but Im not up to fix it.

If you used to (and still) use Subversion, you may not be able to get rid of your muscle memory when you need to check the status of a Git repository. For me, one out of two times, I would type:
git st
It is hardwired in me and Mercurial (Hg) has st as a shortcut, so it gets harder to remember to type the full command when I am using Git.

Git has alias configuration to customize the environment, check out man git-config. You can create a global (meaning for all repositories) alias for status command by typing:
git config --global --add alias.st status
It adds a new entry to global Git configuration file ~/.gitconfig:
[alias]
   st = status
You can manually edit the file if you want. Instead, you can create local alias command which only be used by single repository and configuration is stored in that repository only. But for status command alias, global availability suits better.

ci is a good one to be added for commit command, the second common command for me to get error message from Git, but that's history, too.

If you have used GitHub, you must have already been familiar with gh-pages branch.

I don't like have different code base from the pages branch, so in my projects, master == gh-pages, and many of projects are doing the same. If you have documents like library reference which is generated by source, then you probably will use different base.

For a very long time, I had to do with these commands as follow in order to update that branch:
git checkout gh-pages
git pull . gh-pages
git push
git checkout master

It was just plain silly of me. I did google for it, but not RTFM, I didn't get any useful results, probably used wrong keywords. I finally found the correct answer with correct search keywords, here is the answer:
git push origin master:gh-pages

Here is from manpage git-push:
<refspec>...
    The format of a <refspec> parameter is an optional plus +, followed by the source ref <src>, followed by a colon :,
    followed by the destination ref <dst>. It is used to specify with what <src> object the <dst> ref in the remote
    repository is to be updated.
    [...]
    The <dst> tells which ref on the remote side is updated with this push. Arbitrary expressions cannot be used here, an
    actual ref must be named. If :<dst> is omitted, the same ref as <src> will be updated.

Well, it's all in the manual and I was actually using a shorthand by omitting the <dst>. It's good to know.

So what if you try to omit <src> part? (I am glad I already know about this. Hehe, I am bad!)
git push origin :remote-branch

Note

a new blog post and new version of this script have been published, it adds new option for Commit calendar like Contributions calendar in a GitHub profile page. (2013-02-03T17:30:40Z)

Here is the quick stuff to understand what this is:

$ vcsstat.sh -h

vcsstat.sh [''|AUTHOR_NAME [''|HG_DATESPEC [''|GIT_SINCE [''|GIT_UNTIL]]]]

Every argument is basically optional, however you need to use '' to indicate
that you are not specifying it.

HG_DATESPEC Examples
====================

  "2011-08"
  "2011-01 to 2011-03" # Jan. to Mar. in 2011
  ">2011-05"           # Since May.
  "-3"                 # Last three days

See hg manpage for DATE FORMATS section.

GIT_SINCE and GIT_UNTIL Examples
================================

  "2011-01-23"
  "yesterday"
  "2 weeks ago"

See..., uhm I have no idea where to look at. gitrevisions manpage for
date specification, perhaps?

You can grab the script here.

The script will list all directories and look for VCSes special hidden directory. Currently (and probably only will be), it only supports Git and Mercurial (Hg). As you can see, there are two types datespec used. Git and Hg have some differences, I need to separate into two.

Its MITd and hosted on GitHub, feel free to request features or even better, open pull requests! (Patch might be more suitable, or you need to publicly fork my dotfiles on GitHub).

I wrote this because I believed I had caffeine overdose (xD), but clearly, from the screenshot above, I didnt have.

Gotta have my cup, gotta have caffeine!

Shoot! Its already Saturday.

(I know, I know its old but still have too much caffeine in my brain, thats all I can come up with. ;)

Edit: Damn forgot this blogs timezone is set to Pacific time Its still FRIDAY, YEAH!

*** WARNING: This blog owner is BUI (Blogging Under Influence)! ***

I created a project on github for mirroring my project on Google Code. I am new to git, so maybe there is a better way to do this.

First clone the Subversion repository and push to the Git:
git svn clone https://foo.googlecode.com/svn/ git-foo
cd git-foo
git remote add git-foo git@github.com:username/foo.git
git push git-foo master
After committing in the Subversion repository, run
cd /path/to/git-foo
git svn fetch
git svn rebase
git push git-foo master