CommonThread

Displaying articles with tag

Cherry-Pickin' in Git

Posted by ben, Sat Apr 19 09:47:00 UTC 2008

if you are trying to update to a specific commit of a git repository and can’t seem to get git pull to allow you pull that specific commit, that is because it doesn’t work that way. so you type git to see what command are available but it only shows you these common commands none of which are useful for this:

usage: git [--version] [--exec-path[=GIT_EXEC_PATH]] [-p|--paginate|--no-pager] [--bare] [--git-dir=GIT_DIR] [--work-tree=GIT_WORK_TREE] [--help] COMMAND [ARGS]

The most commonly used git commands are:
   add        Add file contents to the index
   bisect     Find the change that introduced a bug by binary search
   branch     List, create, or delete branches
   checkout   Checkout and switch to a branch
   clone      Clone a repository into a new directory
   commit     Record changes to the repository
   diff       Show changes between commits, commit and working tree, etc
   fetch      Download objects and refs from another repository
   grep       Print lines matching a pattern
   init       Create an empty git repository or reinitialize an existing one
   log        Show commit logs
   merge      Join two or more development histories together
   mv         Move or rename a file, a directory, or a symlink
   pull       Fetch from and merge with another repository or a local branch
   push       Update remote refs along with associated objects
   rebase     Forward-port local commits to the updated upstream head
   reset      Reset current HEAD to the specified state
   rm         Remove files from the working tree and from the index
   show       Show various types of objects
   status     Show the working tree status
   tag        Create, list, delete or verify a tag object signed with GPG

What you need is git cherry-pick which allows you to update to a specific commit.

usage: git-cherry-pick [options] <commit-ish>

    -n, --no-commit       don't automatically commit
    -e, --edit            edit the commit message
    -x                    append commit name when cherry-picking
    -r                    no-op (backward compatibility)
    -m, --mainline <n>    parent number

git cherry-pick will do a fetch and merge to any commit object and then do an auto commit for you. It will automatically use the commit message of that the select commit object. IF you wish to use a different message use the -e option.

0 comments | Filed Under: | Tags:

Setting Up a Git Server

Posted by ben, Sun Apr 13 21:07:00 UTC 2008

Setting up a remote git server is as easy as setting up a new user. In fact if you have git installed on the machine that is about all you need to do. We will not discuss setting up git … just how to set it up to be used as a remote repository.

Setup git User

First we need to setup a user with a home folder. We will store all the repositories in this users home folder.

sudo adduser git

Rather than giving out the password to the git user account use ssh keys to login so that you can have multiple developers connect securely and easily.

Create a Repository

Next we will make a repository. For this example we will work with a repository called example. Login as the user git and add the repository.

# login to remote server
ssh git@REMOTE_SERVER

# once logged in
mkdir example.git
cd example.git
git --bare init

That’s all there is to creating a repository. Notice we named our folder with a .git extension.

Also notice the ‘bare’ option. By default the git repository assumes that you’ll be using it as your working directory, so git stores the actual bare repository files in a .git directory alongside all the project files. Since we are setting up a remote server we don’t need copies of the files on the filesystem. Instead, all we need are the deltas and binary objects of the repository. By setting ‘bare’ we tell git not to store the current files of the repository only the diffs. This is optional as you may have need to be able to browse the files on your remote server.

Commit to Remote Repository

Finally all you need to do is add your files to the remote repository. We will assume you don’t have any files yet.

mkdir example
cd example
git init
touch README
git add README
git commit -m 'first commit'
git remote add origin git@REMOTE_SERVER:example.git
git push origin master

replace REMOTE_SERVER with your server name or IP

4 comments | Filed Under: | Tags:

Categories