Archive

Archive for the ‘git’ Category

Git merging

May 4th, 2009 2 comments

OK, so maybe you can see a bit of a pattern here. I’ve been messing with git trying to get to the point where I can do what I want with it. Now that I understand how the branching functions, the next step was figuring out how to merge.

First thing to note is that this is how you can see the file differences in the two branches:
git diff ––name–status master..branch
Other views of the data:
git diff master..branch
git log master..branch
git shortlog master..branch

So that covers what the differences are between the branches before merging. Then there’s the real merging.
git merge branch ––no–commit

Then you can look at the changes with:
git status
git diff

If you see any problems you can turn back the clock with this:
git reset ––hard

Categories: git Tags:

Git branching warning

May 4th, 2009 No comments

When branching in git it is important to understand the meaning of branches. Branching needs to have state, so if any files are not commited, switching contexts between branches does not make sense. If you want to switch branches you should first commit the changes you’ve made to the branch OR stash your changes with the git stash command.

I’m still getting used to git, and what I was doing was modifying the same file in two different branches. I was constantly switching contexts through git checkout and everything was getting very confusing.

So just make sure that when switching contexts between branches that you either commit your changes to the branch you’re switching from or stashing away those changes.

Categories: git Tags:

Transfer SVN “Branch” into git branch

May 4th, 2009 No comments

There are easier ways to do this, but if you cannot use git-svn for whatever reason you can follow these directions.

  1. Start at the trunk level of your svn checkout and initialize git:
    git init
  2. Then exclude the subversion folders, by adding the following line to “.git/info/exclude”:
    .svn
    *.pyc
  3. Commit all the code:
    git add .
    git commit -m "Initial import of trunk"
  4. Create branch and move into branch:
    git checkout -b svn_branch
  5. Now merge the subversion changes into this git branch (check out this short post). So what’s actually happening is since your in the git “svn_branch” checkout it will add all your merge changes to that git branch.
    svn merge -r <branch copy rev>:HEAD http://<repo_url>/branches/<name of branch>
  6. At this point check to see if subversion did any merges. Add and commit the changes to the git branch:
    git add .
    git commit -a -m "Import of svn branch"
Categories: git Tags:

SVN branching

April 29th, 2009 1 comment

I’ll preface this post by mentioning that the steps for branching are already out there on the web. I’m more concerned here with the complexities in setting up a branch in SVN, and then move onto showing how to do the same thing in git. Branching discussed on other sites:
- Mosuma.com
- svn book
- stackoverflow “How do I create a branch in SVN”

The actual command looks as such:
svn copy http://mysite.com/trunk http://mysite.com/branches/wonderful_branch

As you’ll notice if you look at the subversion command above, the action of branching is not really a staple of subversion. Essentially you’re taking the codebase as of a certain version, copying the entire trunk and placing it in a new home to work with. This process can be quite aggravating, and unless necessary I really try avoiding it.

At a TechTalk on git, Linus Torvalds actually talks at length about this: http://www.youtube.com/watch?v=4XpnKHJAok8.

If you do brave the current in SVN, just keep in mind that the longer you’re branch is disconnected from trunk, the more merging fun you will have to deal with.

Another thing I’d recommend is removing any branches as soon as you work the changes back into trunk. There’s really no reason for branches to just sit around.

As a tool though, the only time I’d really use a branch in SVN world, is when I’m touching lots of different parts of a system and I just need further testing before bringing my changes to trunk. For the casual change, I’d rather just not deal with that. A better idea is to setup a local repo of some sort and just work off that.


Git

I was curious to see what git was all about. Being an avid Linux user, I can’t say that Linus has led me astray in the past… Also, to see if the branching really did make more sense in that world. I must say that it’s unbelievable. And as Linus said, git really does get you to interact differently with your repository. Because branching is done so well and you switch contexts so easily, I can see myself making branches A LOT more often. How it works is you create a branch and that branch kind of happens in the background. To actually view the branch you have to switch contexts, by calling the git checkout command. Once in that context there’s no drilling down to different branch directories. When you checkout the branch, you’re already in the branch and any changes stay in the branch. Then merging and deleting the branch are also very easy to do. It’s really quite impressive in a, yes that’s how it should be kind of way.

Right now, with subversion, I resist branching unless absolutely necessary. In SVN, it costs a lot (space) to branch, it’s very slow, it’s a pain to setup, and it’s tough to merge back.

And here is what it looks like in git (main tutorial)

Initializing a project (run these command within directory of project)
$ git init
$ git add .
$ git commit -m "Initial test"

Editing a file
$ vi modify_some_file
$ git add modify_some_file
$ git commit -m "Test"

Ok, now back to the topic of merging.
Create the branch and check it out. (‘git branch’ shows you which branch is the active branch)
$ git branch
$ git branch new_branch
$ git branch
$ git checkout new_branch
$ git branch

Edit a file
$ vi perl.txt
$ git commit -a -m "Expermintal test"

Change context to main branch (master)
$ git checkout master
$ less perl.txt

Merge new branch
$ git merge new_branch
$ less perl.txt

Delete the branch
$ git branch -d new_branch

Categories: git, Subversion Tags: