Advanced Git usage: Difference between revisions
No edit summary |
|||
Line 1: | Line 1: | ||
__FORCETOC__ | __FORCETOC__ | ||
'''''[[Using patches to share your updates with others|Previous]] | [[Git and Github tutorials|Next]] | [[Guide to using Git with GEOS-Chem]] | [[Getting Started with GEOS-Chem]] | [[Main Page|GEOS-Chem Main Page]]''''' | |||
== Overview == | == Overview == | ||
Line 72: | Line 74: | ||
--[[User:Bmy|Bob Yantosca]] ([[User talk:Bmy|talk]]) 17:03, 21 June 2019 (UTC) | --[[User:Bmy|Bob Yantosca]] ([[User talk:Bmy|talk]]) 17:03, 21 June 2019 (UTC) | ||
---- | |||
'''''[[Using patches to share your updates with others|Previous]] | [[Git and Github tutorials|Next]] | [[Guide to using Git with GEOS-Chem]] | [[Getting Started with GEOS-Chem]] | [[Main Page|GEOS-Chem Main Page]]''''' |
Revision as of 17:06, 21 June 2019
Previous | Next | Guide to using Git with GEOS-Chem | Getting Started with GEOS-Chem | GEOS-Chem Main Page
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:
- master represents the current stable version (in this example, 12.3.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:
- You're working in branch my_branch of your local GEOS-Chem code directory.
- 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.
- 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:
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:
(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.
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)
Previous | Next | Guide to using Git with GEOS-Chem | Getting Started with GEOS-Chem | GEOS-Chem Main Page