Difference between revisions of "Advanced Git usage"

From Geos-chem
Jump to: navigation, search
(Reverting to an older state of the code)
(Cherry-picking individual commits from another branch)
Line 57: Line 57:
 
(3) '''Locate the commit''' entitled <tt>"Remove obsolete LAVHRRLAI and LMODISLAI from input.geos"</tt> in the revision history window.
 
(3) '''Locate the commit''' entitled <tt>"Remove obsolete LAVHRRLAI and LMODISLAI from input.geos"</tt> in the revision history window.
  
(4) '''Right-click with them mouse''' on the commit entitled <tt>"Remove obsolete LAVHRRLAI and LMODISLAI from input.geos"</tt>
+
(4) '''Right-click with them mouse''' on the commit entitled <tt>"Remove obsolete LAVHRRLAI and LMODISLAI from input.geos"</tt>.
  
 
(5) A context menu will appear.  '''Select''' the '''Cherry-pick this commit''' option:
 
(5) A context menu will appear.  '''Select''' the '''Cherry-pick this commit''' option:

Revision as of 17:04, 21 June 2019


Overview

On this page we discuss how some of the more advanced things you can do with Git.

Reverting to an older state of the code

When you clone GEOS-Chem from the remote repository to your local disk space (with the git clone command), the master branch will point to current stable GEOS-Chem version. However, you may want to revert to an older state of the code. Git allows you to do this very easily.

Let's assume that the latest version of the code is 12.3.2 but that you want to use version 12.0.0. The procedure is as follows:

(1) Change to your local GEOS-Chem source code folder.

cd /path/to/your/GEOS-Chem/Code

(2) Start Gitk.

gitk --all &

(3) View the revision history with Gitk.

(4) Locate the commit in the revision history window corresponding to version 12.0.0. This should be marked with a yellow tag.

(5) Right-click with the mouse on the name of the commit. A context menu will appear.

(6) Select the Create new branch menu item. A dialog box will appear.

(7) Type the name of the new branch. For this example, use the name dev/12.0.0

That's it. You now have two branches:

  1. master represents the current stable version (in this example, 12.3.2)
  2. dev/12.0.0 represents GEOS-Chem version 12.0.0

Also note: Using this method, you can check out a new branch from any commit, not just those commits that correspond to GEOS-Chem releases.

Cherry-picking individual commits from another branch

Git allows you to cherry-pick commits, that is to pull a single commit from a different branch into the branch you are currently working on. This can prove useful in many situations. For example, a colleague may have committed a critical bug fix into his or her development version of GEOS-Chem. You may want to only grab that particular bug fix into your current branch without also getting all the other changes that your colleague made.

The best way to cherry-pick commits is via the gitk browser Here is a simple example. Let's assume the following:

  1. You're working in branch my_branch of your local GEOS-Chem code directory.
  2. You've pulled the branch containing your colleague's bug fix update into a new branch of your local code directory called Bug-fix-branch.
  3. You are only interested in merging the commit labeled "Remove obsolete LAVHRRLAI and LMODISLAI from input.geos" into my_branch.

(1) Start Gitk.

gitk --all &

(2) View the revision history in the upper-left Gitk window:

Cherry pick 1.jpg

As you can see, my_branch is displayed in boldface, which indicates that is the current checked out branch.

(3) Locate the commit entitled "Remove obsolete LAVHRRLAI and LMODISLAI from input.geos" in the revision history window.

(4) Right-click with them mouse on the commit entitled "Remove obsolete LAVHRRLAI and LMODISLAI from input.geos".

(5) A context menu will appear. Select the Cherry-pick this commit option:

Cherry pick 2.jpg

(6) View the revision history in the upper-left Gitk window again:

Note that my_branch now displays higher than Bug-fix-branch in the gitk browser revision history window, because it now has the most recent commit.

Cherry pick 3.jpg

If the commit that you brought into my_branch comes from a base version of GEOS-Chem that is significantly different than the your version, he cherry-pick operation may generate conflicts that you will have to manually resolve.

--Bob Yantosca (talk) 17:03, 21 June 2019 (UTC)