User Tools

Site Tools


devs:usegit

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
devs:usegit [2022/04/05 15:53]
helene [2.3 Commit]
devs:usegit [2022/04/05 16:40] (current)
helene
Line 69: Line 69:
 === 2.3.2 Committing a part of your changes === === 2.3.2 Committing a part of your changes ===
 Example: I modified the subroutine CHAB.F to correct some calculation,​ and I deleted useless comments in CHABDAM.F. These are two different changes that should be committed separately. In a first time, I am only going to commit the changes made in CHABDAM.F by using the '​indexing'​ function. Only the changes made to the indexed routines will be taken into account in the commit (see <imgref image9>​). Example: I modified the subroutine CHAB.F to correct some calculation,​ and I deleted useless comments in CHABDAM.F. These are two different changes that should be committed separately. In a first time, I am only going to commit the changes made in CHABDAM.F by using the '​indexing'​ function. Only the changes made to the indexed routines will be taken into account in the commit (see <imgref image9>​).
 +
 <​imgcaption image9|>​{{ :​devs:​commit2.png?​nolink&​600 |}}</​imgcaption>​ <​imgcaption image9|>​{{ :​devs:​commit2.png?​nolink&​600 |}}</​imgcaption>​
 +
 +=== 2.3.3 Cancel a local commit ===
 +:!: Use with caution \\
 +\\
 +If you committed changes without pushing the commit on the server, and you realize there is a mistake (wrong commit message, or some changes that should not have been committed were included in the commit), you have 2 solutions to undo the commit:
 +  * Reset and keep changes (--mixed)
 +  * Reset and delete changes (--hard)
 +__Example__:​ I committed changes on CALMAT2 but I want to change my commit message. In <imgref image10>,​ you can view the history of the branch. The red arrow  « origin/​Helene »  indicates the last commit made on the distant branch. The arrow « Helene » indicates the last commit made on my local branch. My local branch is one commit ahead of the server.
 +
 +<​imgcaption image10|>​{{ :​devs:​commit3.png?​nolink&​600 |}}</​imgcaption>​
 +To reset my local branch and delete the last commit, I can right-click on the last commit of the server (here commit 6697b587 « ILAW=21 ; Lecture theta – IVAL 21 »), and select « Reset » and then chose between keeping or deleting changes. In my case, since I only want to change the commit message, I keep the changes so I can commit them again afterwards. \\
 +\\
 +:!: In practice, you could reset your branch to a state preceding the last commit on the server. However, by doing that, you will generate conflicts between the distant and local versions of your branch. These conflicts may turn out to be difficult to solve. For this reason, you should NEVER reset to points anterior to the last commit on the server. Consider that what is on the server is definitive.
 +
 +==== 2.4 Merging ​ ====
 +=== 2.4.1 Merging the changes from the master ===
 +As indicated in section 2.1, pushing and pulling commits in the same branch can be done with the button on the bottom right of the Visual Studio window. In order to retrieve commits from another branch, the process is a bit more complex. \\
 +\\
 +First of all, make sure you don’t have any pending changes in your branch (otherwise they would be overwritten by the merge). Git will display an error message if that is the case and refuse the merge. You must either commit your changes or delete them. \\
 +\\
 +After that, you will have to retrieve commits from the server: set the master branch as your active branch and make a “pull” or a “fetch”. \\
 +\\
 +You can now merge your branch with the master. Set your branch as the active branch and select “Manage branches”. Right-click on your branch and choose “Merge from…”. In the Team Explorer tab, you will see a drop-down list from which you can select which branch you want to merge from. Select “origin/​master” – it is the distant master branch. Remark: if you pulled the changes in your local master branch, selecting “master” or “origin/​master” should be the same. \\
 +You can now click on “merge”. ​
 +<​imgcaption image11|>​{{ :​devs:​merge1.png?​nolink&​700 |}}</​imgcaption>​
 +Merging the master branch into your branch should be done regularly to keep your version up to date. In particular, you must merge __before__ you make changes in a global subroutine (such as ELEMB, LOI2, LAMIN2, PRISIG, PRISUM, …) in order to avoid conflicts between the master and your branch. ​
 +
 +=== 2.4.2 Merge conflicts ===
 +Example of a merge conflict :
 +  * The developper 1 added a call to a new law in LOI2 and merged his branch into the master branch;
 +  * I add a call to another new law in LOI2, using the LOI2 file that was not updated from the master branch (my LOI2 does not contain the call to the law of developer 1)
 +If I try to merge my branch and the master, I will get a message indicating there is a merge conflict. Visual Studio will then suggest 3 possibilities to solve the conflict:
 +  * “Merge”:​ I will select manually which changes from each version of the code I want to keep;
 +  * “Take source”: I will take the version of the master branch and delete mine;
 +  * “Keep target”: I will keep my version and delete the one from the master.
 +Generally, the 2 last options are not very useful. Indeed, if you consider the example above, this would mean deleting either the call to my law or the call to the law of developer 1. What we want here is a version with call to both laws. \\
 +\\
 +By selecting the “Merge” option, you can create a new version of the source file in conflict by selecting which lines you want to keep. In <imgref image12> for instance, I combined 2 versions that each had a different comment written on the same line. I wanted to keep both comments, so I selected both (the on in the master version and the one in Dev2 version). A new version of the file is generated by visual studio. Once you are satisfied with the new version, you can save it and click on « Accept merge » in the top left corner. The merge can then be made without conflict.
 +
 +<​imgcaption image12|>​{{ :​devs:​merge2.png?​nolink&​600 |}}</​imgcaption>​
 +
 +=== 2.4.3 Merging your changes into the master ===
 +The Master branch is a protected branch, therefore merging into it can only be done on the GitLab website. \\
 +In order to make a merge with GitLab – that is, to put the modification from your branch into the official version of the code (master branch) – it is advised to first merge the master branch into your branch using Visual Studio (see section 2.4.2) to solve potential merge conflicts. \\
 +\\
 +To make the merge in GitLab, go to the Lagamine page ⟶ Repository ⟶ Branches. \\
 +\\
 +You can then click the « Merge request » button corresponding to your branch. You will then have to input a title for the merge (as done for the commits).
 +
 +===== 3 Useful links =====
 +  * Documentation on how to use Git in Visual Studio: https://​docs.microsoft.com/​en-us/​azure/​devops/​repos/​git/​gitquickstart?​view=azure-devops&​tabs=visual-studio-2019
 +  * GitLab documentation:​ https://​docs.gitlab.com/​ee/​index.html
 +
 +
 +
 +
  
devs/usegit.1649166834.txt.gz · Last modified: 2022/04/05 15:53 by helene