1

I've begun trying to contribute to a large (ten million or so lines of C++), famous open-source project by supplying small bugfixes in my free time. The project is managed with Git, which I'm completely new to. I've tried to find information on how best to use it, but all I can seem to find is complicated religious arguments over trivia like whether to use git fetch or git pull. Could anyone tell me, very simply, what commands I need to execute in order to facilitate the following workflow?

  1. Checkout the full source.
  2. Begin working on some feature or bug fix
  3. Continue checking out the full source daily and merging my changes so far with it.
  4. Generating a patch with all the differences between my tree and the remote master repository
  5. (When necessary) rolling back any changes since my last commit
  6. (When necessary) rolling back any differences between my tree and the remote master repository
Brennan Vincent
  • 10,736
  • 9
  • 32
  • 54

2 Answers2

4
  1. Checkout the full source.

    git clone git://url

  2. Begin working on some feature or bug fix

    If you are working on multiple things simultaneously, it is advisable to make separate branches for each feature. These are usually referred to as topic branches.

    git checkout -b <branch name> <desired base commit>

  3. Continue checking out the full source daily and merging my changes so far with it.

    If you use topic branches, a simple git pull will do. Instead if you are working on master (you skipped step (2)), then I would recommend using git pull --rebase. This way your work will be based on the latest tip of master in origin.

  4. Generating a patch with all the differences between my tree and the remote master repository

    Once you are confident you have written a bug free feature (good luck!) you can merge the changes (if you were using topic branches) by git merge master, resolve any conflicts and commit. Then you can generate your patches with

    git format-patch <base commit for your feature>

  5. (When necessary) rolling back any changes since my last commit

    To roll back, you can use git reset <options>. There are several options, I would encourage you to look at man git-reset as the differences are quite subtle. If you want to get rid of your work completely (are you really sure?), the --hard option should do the trick. On the other hand, if you want to revert a committed change with a separate commit, git revert <commit> is your friend.

  6. (When necessary) rolling back any differences between my tree and the remote master repository

    Not sure what you mean here, but if you mean updating the local repo with the latest changes from upstream, I believe (3) addresses that.

suvayu
  • 4,271
  • 2
  • 29
  • 35
1
1$ git clone <repository> <directory>
2$ <edit as you please>     # suggest 'git checkout -b <new branch>' prior to edit
3$ git pull origin master
4$ git push origin master    # you probably won't have permission for this, ask repo admins
5$ git reset --hard
6$ git checkout -b <new branch> origin/master   # not a rollback, just leave your stuff and shift to a new branch.
GoZoner
  • 67,920
  • 20
  • 95
  • 145
  • Thanks! As for number 4, by "generate a patch" I didn't mean push to the repository; I meant generate a patch file that I can send in to a mailing list or bugzilla. – Brennan Vincent Apr 01 '12 at 21:07
  • 1
    Try 'git diff' (by default creates a patch) – GoZoner Apr 01 '12 at 21:09
  • You'll want to do the 'git pull' to ensure you've got the latest from 'origin' and then 'git diff origin/master' to generate the relevant diff' – GoZoner Apr 01 '12 at 21:18