Next: Forcing Changes Up: Bacula Git Usage Previous: Git Usage Contents Index
Subsections

- More Details

# Step by Step Modifying Bacula 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?

- Download the Source code:

      git clone ssh://<userid>@bacula.git.sourceforge.net/gitroot/bacula/bacula trunk

- Configure and Build Bacula:

      ./configure (all-your-normal-options)
      make

- Create a branch to work on:

      cd trunk/bacula
      git checkout -b bugfix master

- Edit, build, Test, ...

      edit file jcr.h
      make
      test

- 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

- When you 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.

## More Details

Normally, you will work by creating a branch of the master branch of your repository, make your modifications, then make sure it is up to date, and finally create format-patch patches or push it to the Source Forge repo. Assuming you call the Bacula repository trunk, you might use the following commands:

    cd trunk
    git checkout master
    git pull
    git checkout -b newbranch master
    (edit, ...)
    git add <file-edited>
    git commit -m "<comment about commit>"
    ...

When you have completed working on your branch, you will do:

    cd trunk
    git checkout newbranch  # ensure I am on my branch
    git pull                # get latest source code
    git rebase master       # merge my code

If you have completed your edits before anyone has modified the repository, the git rebase master will report that there was nothing to do. Otherwise, it will merge the changes that were made in the repository before your changes. If there are any conflicts, Git will tell you. Typically resolving conflicts with Git is relatively easy. You simply make a diff:

    git diff

Then edit each file that was listed in the git diff to remove the conflict, which will be indicated by lines of:

    <<<<<<< HEAD
    text
    >>>>>>>>
    other text
    =====

where text is what is in the Bacula repository, and other text is what you have changed.

Once you have eliminated the conflict, the git diff will show nothing, and you must do a:

    git add <file-with-conflicts-fixed>

Once you have fixed all the files with conflicts in the above manner, you enter:

    git rebase --continue

and your rebase will be complete.

If for some reason, before doing the -continue, you want to abort the rebase and return to what you had, you enter:

    git rebase --abort

Finally to make a set of patch files

    git format-patch -M master

When you see your changes have been integrated and pushed to the main repo, you can delete your branch with:

    git checkout master
    git branch -D newbranch

Next: Forcing Changes Up: Bacula Git Usage Previous: Git Usage Contents Index