Showing posts with label git. Show all posts
Showing posts with label git. Show all posts

Never having uncommitted changes

The other day I was commenting on how quickly a collegue seems to be able to create a new PR for a change. For me I need to

  1. stash my working branch's uncommitted changes, 
  2. switch to main, 
  3. pull down new changes,
  4. make the new branch, 
  5. make the actual change, 
  6. commit the change,
  7. push the branch, 
  8. open PR,
  9. switch back to my working branch, and 
  10. un-stash the uncommitted changes. 

He said, in effect, "I never have uncommitted changes." He also mentioned heavy reuse of his command line history, and I know of his highly customized git config [*]. But it was the idea of never having uncommitted changes that struck me. I think I have finally figured out that I should always be making small, tactical commits rather than waiting for a semantic commit. Then, when ready for the PR, use rebase not just for small reorganizations, but for wholesale reorganization into semantic commits.

* My use of IntelliJ for most git operations precludes these efficiencies.

Pro Git

When learning a new topic it has been my experience that you read several explanations and tutorials and finally, the last one you read makes the topic crystal clear. I don't think it did. It just was there when you finally annealed all that information into those crystals. Anyway, if you are learning git, as I am, even though I have been using it for years, the book Pro Git by Scott Chacon is working for me. I have not finished it yet, but so much is clearer now.

Git and the busy development shop

I don't like Git and this posting is not going to change anyone's mind about Git and I will continue to use Git as it has become the one version control system to rule them all.

Git does not work the way I want a version control tool to work and especially in a busy development shop. I work on multiple branches concurrently. Does anyone have serialized bug and feature work? I don't need the whole version control tree available all the time. I only need the trunk and the branches I am working on and I need them to be available simultaneously. Git's stash, which allows pausing development on one branch to work on another, is useless to me. Using it breaks my work flow and destabilizes my mental model of my file system. That is, when I am in ~/src/foo/branches/issue1/ I know everything below is work being done on issue1, and when I am in ~/src/foo/branches/feature2/ I know everything below is work being done on feature2. There is never any confusion as to what I am looking at. With Git, however, I need to frequently confirm that ~/src/foo/ is currently checked-out for issue1 or feature2. (Cloning to specific issue1 and feature2 directories is not a solution. See following.)

The other issue with Git is with centralized repos. Git's development model assumes many developers, each with their own full copy of the repo, and exchanging updates via patches. I understand this model and see its value. Introducing a centralized repo into this model adds complexity and collateral problems. It is not that the problems are unique to Git, but that a centralized Git repo intensives them. For example, developers A and B work on the same branch and each performs one or more checkins and some number of pushes to the origin (ie, the centralized repo). Since we have 3 repos in play -- A's repo, Bs repo, and the centralized repo -- the chances of a conflict after checkin are very high. Compare this with Subversion where there is only one repo. A and B can work as much as they like and will be stopped to resolve conflicts at checkin and not afterwards. I argue that resolving conflicts at checkin is a far better time to do this work as one's mind is in "differences" mode. When using Git I find myself performing a checkin immediately followed by a push so as to avoid this mess. Doing so loses a key feature of Git, ie distributed version control that works offline.

Update: When I wrote the following I was not aware of interactive rebase. An interactive rebase is used to reorder and combine commits so as to provide a list of changes where each change is functionally complete and the list is in a logical order. The video Interactive git rebase for code reviews and profit is a useful guide to doing that.

I hate Git's rebasing. File A is branched from master. A is changed N times on the branch and a few times on the master. Rebasing A is the equivalent of branching A from the current master and automatically applying the N changes. Doing this ruins the version history and reviewing the version history is the first step in fixing regressions. Other version history fraud comes from deleting branches and so loosing detail about who and when a change was introduced to the branch which are details that are often critical to recontextualizing the "fix". Git can be used without recourse to rebasing and deleting branches, but it seems to be common practice.

Back to coding...

Building and installing the NetBeans Git plugin.

I wanted a NetBeans Git. The only Git plugin that I found that was also current is

http://github.com/myabc/nbgit/tree/master

I tried the 0.1 distribution but it did not work with NetBeans 6.7. So I built it from within NetBeans:

Clone the project...

1) At the command line "git clone git://github.com/myabc/nbgit.git"

Build the module from within Netbeans...

2) Choose File/Open Project... and pick "nbgit".
3) Choose Create NBM from the nbgit project's context menu

Install the module...

4) Choose Tools/Plugins
5) Choose Downloaded
6) Choose Add Plugins...
7) Select the plugin: Mine was at /Users/ajg/Documents/src/nbgit/build/org-nbgit.nbm
8) Restart NetBeans

You can now use the plugin to explore, for example, nbgit.

As far as I can see, there is no NetNeans UI where you can import a project from, for example, github.

Github.com's git training

Wave Syndicate is considering bringing in a trainer from Github.com to do some on-site training. (Wave Syndicate doesn't want me deleting the master branch again.) The trainer would do a couple of lecture style trainings and then some small group tutorials. The cost is $2250. Is anyone else interested in attending and sharing the costs? Email me at andrewgilmartin@3roofs.com.

Git and the horror of the extra colon

Never enter the command line git push origin :master when you mean git push origin master. Instead of coping your master branch's local changes to the remote repository you delete the remote repository's master branch. You can't undo this mistake. My initial reaction to the fact that I just deleted the company's source code was not a comfortable one. What I soon found out, however, was that you can just push again your master branch to return it to the remote repository. I am not sure this is the correct fix but it did seem to work.

Update: Here are my git notes at github.com

On to Git

I was not looking forward to learning Subversion SCM. It just looked too complicated. The basic manual is a few hundred pages. Thank goodness that Git is taking over the SCM world. I can move on from CVS, an old and fond friend, to something that actually works for distributed development.

In my search for Git introductions I found Getting into SCM with Git. Worth reading.