Modifying Code

Suppose you want to download Bacula source code, build it, make a change, then submit your change to the Bacula developers. What would you do?

  • Tell git who you are:
    git config --global user.name "First-name Last-name"
    git config --global user.email "email@address.com"
    

    Where you put your real name and your email address. Since this is global, you only need to do it once on any given machine regardless of how many git repos you work with.

  • Download the Source code:
    git clone http://git.bacula.org/bacula.git bacula
    
  • Configure and Build Bacula:
    ./configure (all-your-normal-options)
    make
    
  • Create a branch to work on:

    cd bacula/bacula
    git checkout -b bugfix Branch-11.0
    
  • Edit, build, Test, …
    edit file jcr.h
    make
    test
    

    Note: if you forget to create a working branch prior to making changes, and you make them on the development branch, this is no problem providing that you create the working branch before your first commit. So assuming that you have edited “master” instead of your bugfix branch, you can simply:

    git checkout -b bugfix master
    

    and a new bugfix branch will be created and checked out. You can then proceed to committing to your bugfix branch as described in the next step.

  • commit your work:

    git commit -am "Short comment on what I did"
    
  • Possibly repeat the above two items

  • Switch back to the master branch:
    git checkout master
    
  • Pull the latest changes:
    git pull
    
  • Get back on your bugfix branch:
    git checkout bugfix
    
  • Merge your changes and correct any conflicts:
    git rebase master bugfix
    
  • Fix any conflicts:
    You will be notified if there are conflicts. The first thing to do is:
    git diff
    

    This will produce a diff of only the files having a conflict. Fix each file in turn. When it is fixed, the diff for that file will go away.

    For each file fixed, you must do the same as SVN, inform git with:

    git add (name-of-file-no-longer-in-conflict)
    
  • When all files are fixed do:

    git rebase --continue
    
  • If you find that it is impossible to reconcile the two branches or you made a mistake in correcting and adding files, before you enter the:

    git rebase --continue
    

    you can instead enter:

    git rebase --abort
    

    which will essentially cancel the the original git rebase and reset everything to the beginning with no changes to your bugfix branch.

  • When you have completed the rebase and are ready to send a patch, do the following:
    git checkout bugfix
    git format-patch -M master
    

    Look at the files produced. They should be numbered 0001-xxx.patch where there is one file for each commit you did, number sequentially, and the xxx is what you put in the commit comment.

  • If the patch files are good, send them by email to the developers as attachments.

  • Then you can continue working on your code if you want, or start another branch with a new project.

  • If you continue working on your bugfix branch, you should do a git rebase master from time to time, and when your changes are committed to the repo, you will be automatically synchronized. So that the next git format-patch will produce only the changes you made since the last format-patch you sent to the developers.

More details about modifying code:

Possible Next Steps

Go to Forcing Changes.

Go back to Publishing Code.

Go back to Developer Guide.