Difference between revisions of "Committing"

From Geos-chem
Jump to: navigation, search
(Renaming or moving files)
 
(12 intermediate revisions by the same user not shown)
Line 1: Line 1:
'''''[[Branching|Previous]] | [[Tagging|Next]] | [[Guide to using Git with GEOS-Chem]] | [[Getting Started with GEOS-Chem]] | [[Main Page|GEOS-Chem Main Page]]'''''
+
'''''[[Branching|Previous]] | [[Tagging|Next]] | [[Guide to using Git with GEOS-Chem]] | [[Getting Started with GEOS-Chem]]'''''
 +
 
 +
#[[Introduction to Git]]
 +
#[[Installing Git]]
 +
#[[First-time Git setup]]
 +
#[[Cloning (i.e. downloading for the first time)]]
 +
#[[Ignoring files]]
 +
#[[Viewing the revision history]]
 +
#[[Using Git GUI]]
 +
#[[Branching]]
 +
#<span style="color:blue">'''Committing'''</span>
 +
#[[Tagging]]
 +
#[[Merging]]
 +
#[[Receiving updates (aka pulling)]]
 +
#[[Using patches to share your updates with others]]
 +
#[[Advanced Git usage]]
 +
#[[Git and Github tutorials]]
 +
 
  
 
== Overview ==
 
== Overview ==
Line 11: Line 28:
 
Committing is best done with the [[Using Git GUI|Git GUI]].   
 
Committing is best done with the [[Using Git GUI|Git GUI]].   
  
1. Start the Git GUI:
+
(1) '''Start Git GUI'''.
  
 
  git gui &
 
  git gui &
  
2. Pick '''Commit/Rescan''' from the menu (or type the F5 key) to force the '''git gui''' to show the latest changes.
+
(2) Select '''Commit/Rescan''' from the menu (or type the F5 key) to force Git GUI to show the latest changes.
  
 
[[Image:GitGuiCommitMenu.png]]
 
[[Image:GitGuiCommitMenu.png]]
  
3. You should see a list of files in the '''Unstaged Changes''' window. These are files that have been modified.
+
(3) You should see a list of files in the '''Unstaged Changes''' window. These are files that have been modified.
  
4. Stage your changes (i.e. tell Git to add the modifications to the revision history).  This can be done in one of two ways:
+
(4) '''Stage your changes''' (i.e. tell Git to add the modifications to the revision history).  This can be done in one of two ways:
 
*Click on the icons at the left of each file name in the '''Unstaged Changes''' window, OR
 
*Click on the icons at the left of each file name in the '''Unstaged Changes''' window, OR
 
*Click on the '''Stage Changed''' button.  (WARNING: This will stage ALL changes!)
 
*Click on the '''Stage Changed''' button.  (WARNING: This will stage ALL changes!)
  
5. If you need to remove a file from '''Staged Changes''', just click on its icon.  It will be moved back to '''Unstaged Changes'''.  Git will not include that file in the revision history.
+
(5) If you need to remove a file from '''Staged Changes''', just click on its icon.  It will be moved back to '''Unstaged Changes'''.  Git will not include that file in the revision history.
  
6. Type a '''Commit message''' in the bottom right window.  [https://github.com/erlang/otp/wiki/Writing-good-commit-messages See this example of a good commit message].  Some pointers are:
+
(6) '''Type a commit message''' in the bottom right window.  [https://github.com/erlang/otp/wiki/Writing-good-commit-messages See this example of a good commit message].  Some pointers are:
 
*The first line should only be 50 characters or less and succinctly describe the commit
 
*The first line should only be 50 characters or less and succinctly describe the commit
 
*Then leave a blank line
 
*Then leave a blank line
 
*Then add more in-depth text that describes the commit
 
*Then add more in-depth text that describes the commit
  
7. Click on the '''Sign off''' button.  This will add your name, email address, and a timestamp.   
+
(7) '''Click''' on the '''Sign off''' button.  This will add your name, email address, and a timestamp.   
 
*To modify your name and email address, edit the <tt>.gitconfig</tt> file in your home directory, as described in ''[[First-time Git setup]]''.
 
*To modify your name and email address, edit the <tt>.gitconfig</tt> file in your home directory, as described in ''[[First-time Git setup]]''.
  
8. Select one of the two radio buttons above the '''Commit message''' window.
+
(8) '''Select''' one of the two radio buttons above the '''Commit message''' window.
 
*'''New commit:''' This is the default.  Assumes you are making a totally new commit.
 
*'''New commit:''' This is the default.  Assumes you are making a totally new commit.
 
*'''Amend last commit:''' If for whatever reason you need to update the last commit message, pick this button.
 
*'''Amend last commit:''' If for whatever reason you need to update the last commit message, pick this button.
  
9. Click on the '''Commit''' button.
+
(9) '''Click''' on the '''Commit''' button.
  
10. [[Viewing the revision history|View the revision history]].  You should see your new commit.
+
(10) [[Viewing the revision history|'''View the revision history''']] again.  You should see your new commit.
  
 
== Renaming or moving files ==
 
== Renaming or moving files ==
Line 51: Line 68:
 
To rename a file, follow these steps:
 
To rename a file, follow these steps:
  
# Change the name of the file with the Unix <tt>mv</tt> command.   
+
(1) Change the name of the file with the Unix <tt>mv</tt> command.   
#*e.g.: <tt>mv myfile.f myfile.F</tt>.
+
*e.g.: <tt>mv myfile.f myfile.F</tt>.
# Open the '''git gui'''.  You will see the two files <tt>myfile.f</tt> and <tt>myfile.F</tt> listed in the '''Unstaged Changes''' window.   
+
 
#Click on <tt>myfile.f</tt> and <tt>myfile.F</tt>; this will move them to the '''Staged Changes''' window.   
+
(2) Open the '''git gui'''.  You will see the two files <tt>myfile.f</tt> and <tt>myfile.F</tt> listed in the '''Unstaged Changes''' window.   
# In '''Staged Changes''' you will see:
+
 
##File <tt>myfile.f</tt> is slated to be removed (i.e. a red "X" is listed next to the file name).
+
(3) Click on <tt>myfile.f</tt> and <tt>myfile.F</tt>; this will move them to the '''Staged Changes''' window.   
##File <tt>myfile.F</tt> is slated to be added (i.e. a green checkmark is listed next to the file name).
+
 
# Add a commit message, sign off, and click '''Commit''' [[#Creating a commit with Git GUI|Committing|as described above]].
+
(4) In '''Staged Changes''' you will see:
# Start the '''gitk''' browser.  In the lower left window, you should see text such as:
+
*File <tt>myfile.f</tt> is slated to be removed (i.e. a red "X" is listed next to the file name).
 +
*File <tt>myfile.F</tt> is slated to be added (i.e. a green checkmark is listed next to the file name).
 +
 
 +
(5) Add a commit message, sign off, and click '''Commit''' [[#Creating a commit with Git GUI||as described above]].
 +
 
 +
(6) Start the '''gitk''' browser.  In the lower left window, you should see text such as:
  
 
   ---------------- GeosCore/myfile.F --------------------------
 
   ---------------- GeosCore/myfile.F --------------------------
Line 72: Line 94:
 
If you need to move a file to a new folder, then follow these steps:
 
If you need to move a file to a new folder, then follow these steps:
  
#Move the file to a new folder.
+
(1) Move the file to a new folder.
#*e.g. mv GeosCore/myfile.F NewFolder/myfile.F.
+
*e.g. <tt>mv GeosCore/myfile.F NewFolder/myfile.F.</tt>
# Open the '''git gui'''.  You will see the two files <tt>myfile.f</tt> and <tt>myfile.F</tt> listed in the '''Unstaged Changes''' window.   
+
 
#Click on <tt>myfile.F</tt> and <tt>NewFolder/myfile.F</tt>; this will move them to the '''Staged Changes''' window.   
+
(2) Open the '''git gui'''.  You will see the two files <tt>myfile.f</tt> and <tt>myfile.F</tt> listed in the '''Unstaged Changes''' window.   
# In '''Staged Changes''' you will see:
+
 
##File <tt>myfile.F</tt> is slated to be removed (i.e. a red "X" is listed next to the file name).
+
(3)Click on <tt>myfile.F</tt> and <tt>NewFolder/myfile.F</tt>; this will move them to the '''Staged Changes''' window.   
##File <tt>NewFolder/myfile.F</tt> is slated to be added (i.e. a green checkmark is listed next to the file name).
+
 
# Add a commit message, sign off, and click '''Commit''' [[#Committing|as described above]].
+
(4) In '''Staged Changes''' you will see:
# Start the '''gitk''' browser.  In the lower left window, you should see text such as:
+
*File <tt>myfile.F</tt> is slated to be removed (i.e. a red "X" is listed next to the file name).
 +
*File <tt>NewFolder/myfile.F</tt> is slated to be added (i.e. a green checkmark is listed next to the file name).
 +
 
 +
(5) Add a commit message, sign off, and click '''Commit''' [[#Creating a commit with Git GUI|as described above]].
 +
 
 +
(6) Start the '''gitk''' browser.  In the lower left window, you should see text such as:
  
 
   ---------------- NewFolder/myfile.F --------------------------
 
   ---------------- NewFolder/myfile.F --------------------------
Line 93: Line 120:
 
== Further reading ==
 
== Further reading ==
  
TBD
+
#[https://git-scm.com/docs/git-commit ''Git commit'' (Git documentation)]
 +
#[https://www.git-tower.com/learn/git/commands/git-commit ''Git commit'' (Git Tower)]
 +
#[https://www.atlassian.com/git/tutorials/saving-changes/git-commit ''Git commit'' (Atlassian Git tutorial)]
 +
 
  
 
----
 
----
'''''[[Branching|Previous]] | [[Tagging|Next]] | [[Guide to using Git with GEOS-Chem]] | [[Getting Started with GEOS-Chem]] | [[Main Page|GEOS-Chem Main Page]]'''''
+
'''''[[Branching|Previous]] | [[Tagging|Next]] | [[Guide to using Git with GEOS-Chem]] | [[Getting Started with GEOS-Chem]]'''''

Latest revision as of 20:28, 5 August 2019

Previous | Next | Guide to using Git with GEOS-Chem | Getting Started with GEOS-Chem

  1. Introduction to Git
  2. Installing Git
  3. First-time Git setup
  4. Cloning (i.e. downloading for the first time)
  5. Ignoring files
  6. Viewing the revision history
  7. Using Git GUI
  8. Branching
  9. Committing
  10. Tagging
  11. Merging
  12. Receiving updates (aka pulling)
  13. Using patches to share your updates with others
  14. Advanced Git usage
  15. Git and Github tutorials


Overview

On this page, we provide instructions on how to commit source code changes with Git.

Creating a commit with Git GUI

With Git, you should commit frequently, such as when you have completed making revisions to a file or group of files. Commits that are made on one branch will not affect the other branches.

Committing is best done with the Git GUI.

(1) Start Git GUI.

git gui &

(2) Select Commit/Rescan from the menu (or type the F5 key) to force Git GUI to show the latest changes.

GitGuiCommitMenu.png

(3) You should see a list of files in the Unstaged Changes window. These are files that have been modified.

(4) Stage your changes (i.e. tell Git to add the modifications to the revision history). This can be done in one of two ways:

  • Click on the icons at the left of each file name in the Unstaged Changes window, OR
  • Click on the Stage Changed button. (WARNING: This will stage ALL changes!)

(5) If you need to remove a file from Staged Changes, just click on its icon. It will be moved back to Unstaged Changes. Git will not include that file in the revision history.

(6) Type a commit message in the bottom right window. See this example of a good commit message. Some pointers are:

  • The first line should only be 50 characters or less and succinctly describe the commit
  • Then leave a blank line
  • Then add more in-depth text that describes the commit

(7) Click on the Sign off button. This will add your name, email address, and a timestamp.

  • To modify your name and email address, edit the .gitconfig file in your home directory, as described in First-time Git setup.

(8) Select one of the two radio buttons above the Commit message window.

  • New commit: This is the default. Assumes you are making a totally new commit.
  • Amend last commit: If for whatever reason you need to update the last commit message, pick this button.

(9) Click on the Commit button.

(10) View the revision history again. You should see your new commit.

Renaming or moving files

In some instances you may find it necessary to rename files or move files to a new folder. For example, in GEOS-Chem v9-01-02, we have had to rename file ending in .f to .F and .f90 to .F90. If only the name of the file changes, then Git will recognize it as a renamed file in the repository.

Renaming files

To rename a file, follow these steps:

(1) Change the name of the file with the Unix mv command.

  • e.g.: mv myfile.f myfile.F.

(2) Open the git gui. You will see the two files myfile.f and myfile.F listed in the Unstaged Changes window.

(3) Click on myfile.f and myfile.F; this will move them to the Staged Changes window.

(4) In Staged Changes you will see:

  • File myfile.f is slated to be removed (i.e. a red "X" is listed next to the file name).
  • File myfile.F is slated to be added (i.e. a green checkmark is listed next to the file name).

(5) Add a commit message, sign off, and click Commit |as described above.

(6) Start the gitk browser. In the lower left window, you should see text such as:

  ---------------- GeosCore/myfile.F --------------------------
  similarity index 100%
  rename from GeosCore/myfile.f
  rename to GeosCore/myfile.F

From this point forward, file myfile.F will use the *.F file extension. However, it will still possess the total revision history from when the file was still named myfile.f. If you merge changes from another repository that still has myfile.f, then these changes will be seamlessly integrated into myfile.F.

Moving files

If you need to move a file to a new folder, then follow these steps:

(1) Move the file to a new folder.

  • e.g. mv GeosCore/myfile.F NewFolder/myfile.F.

(2) Open the git gui. You will see the two files myfile.f and myfile.F listed in the Unstaged Changes window.

(3)Click on myfile.F and NewFolder/myfile.F; this will move them to the Staged Changes window.

(4) In Staged Changes you will see:

  • File myfile.F is slated to be removed (i.e. a red "X" is listed next to the file name).
  • File NewFolder/myfile.F is slated to be added (i.e. a green checkmark is listed next to the file name).

(5) Add a commit message, sign off, and click Commit as described above.

(6) Start the gitk browser. In the lower left window, you should see text such as:

  ---------------- NewFolder/myfile.F --------------------------
  similarity index 100%
  rename from GeosCore/myfile.F
  rename to NewFolder/myfile.F

From this point forward, file NewFolder/myfile.F will still possess the total revision history from when the file was still named GeosCore/myfile.F. If you merge changes from another repository that still has GeosCore/myfile.F, then these changes will be seamlessly integrated into NewFolder/myfile.F.

--Bob Yantosca (talk) 15:56, 20 June 2019 (UTC)

Further reading

  1. Git commit (Git documentation)
  2. Git commit (Git Tower)
  3. Git commit (Atlassian Git tutorial)



Previous | Next | Guide to using Git with GEOS-Chem | Getting Started with GEOS-Chem