GIT: a regular session of development
This information is for Scilab developers and code contributors. See GIT for a table of content. If you are a user of Scilab, you probably don't need to look at this.
In this page, we describe a regular git session during the development of Scilab. The following sequence of git statements allows to avoid several issues. It also allows to manage the connection with Gerrit, our source code reviewing system. The typical issue to avoid is a conflict on the CHANGES file, as we all have to update this file when we fix a bug.
Contents
Summary of the process
Here is a summary.
1. Create the commit
2. Get the updates, push the commit
3. Getting clean back again
4. Working with branches
If you are working on several bugs you might want to work on several patches at the same time. Because the code review process may take some time and require you to update a patch you submitted while you are working on some other issues, you will often have to switch your working environment so as not to interfere with your works in progress.
In order to achieve this, git is a great buddy because git works very well with branches. Branches will let you work on different patchsets without having to clone several repositories. It will also let you work on local branches where you can create as many personal commits that will not interfere with the public project, provided you follow the guidelines presented here.
1 ## Use one of these methods to move to your local branch
2 ## Method 1 ##
3 git checkout -b bug_xxxxx # will create the local branch bug_xxxxx and move your HEAD to it
4 ## Method 2 ##
5 git branch bug_xxxxx # will create the local branch bug_xxxxx
6 git checkout bug_xxxxx # will move your HEAD to the branch bug_xxxxx
7
8 ## =========================
9 ## Work on your local branch
10 ## =========================
11 git branch # will list your local branches
12 git checkout bug_xxxxx # will move your HEAD to the branch bug_xxxxx
13
14 ## edit changes and commit
15 git add myfile.txt # stages myfile.txt to be commited
16 git commit -m "my commit message" # will create the commit
17
18 ## because you are on a local branch you can edit
19 ## and commit as much as you want
20 ## your branch is local so you are the only one concerned
21 ## with the commits...
22
23 ## =======================================
24 ## creating the commit that will be public
25 ## =======================================
26 git checkout master # will move HEAD to master
27 git pull # will get back most recent validated commits
28 git merge bug_xxxxx # will create a commit with all changes in the branch bug_xxxxx
29
30 ## edit commit message to something relevant
31 git push # will publish the commit on the codereview
32 git reset --hard HEAD^ # will remove the commit created to clean up your master
33
34 ## ================================
35 ## Modifying your commit afterwards
36 ## ================================
37
38 ## Oh I got a bad review on my commit I need to do some changes
39 ## Move back to your edit branch
40 git checkout bug_xxxxx
41 ## Cherry pick the commit from the code review
42 ## You have access to it from the download menu
43
44 ## Do your changes and merge again on master
45 git checkout master
46 git merge bug_xxxxx
47 ## make sure your edit has the proper Change-ID for gerrit to know where to push it
48 git push
49
50 ## ===========================================
51 ## Remove branches when you are done with them
52 ## ===========================================
53
54 ## remove them when the commit is merged for instance
55 git branch -d bug_xxxxx # will remove the local branch bug_xxxxx
56
5. Resolving conflicts
When cherry-picking, merging or rebasing, you might have conflicts.
Git doesn't let you finish the operation until you have resolved them
1 ## After a cherry-pick, rebase or merge operation with conflict
2 git status # will tell you the conflicted files
3
4 ## files in conflicts are not staged!
5 ## solve the issue by editing them manually (for instance)
6 ## you can pinpoint a conflict by grepping <<<<<
7
8 git add myfile.txt # once resolved stage the files
9 git cherry-pick --continue # to finish your cherry-pick
10 git rebase --continue # to finish your rebase
11 git merge --continue # to finish your merge
12
13 ## Please remove the conflict files in the commit message
14 ## they mess up with gerrit and the Change-ID and gerrit won't
15 ## let you push
16
Here is the detailed process for all operations.
Create the commit
myname@MYMACHINE /f/mygitrepository/scilab/scilab (master) $ git status # On branch master # Changed but not updated: # (use "git add <file>..." to update what will be committed) # (use "git checkout -- <file>..." to discard changes in working directory) # # modified: CHANGES_5.3.X # modified: RELEASE_NOTES_5.3.X # modified: modules/statistics/src/dcdflib/cdfbet.f # modified: modules/statistics/src/dcdflib/cdfbin.f [...] # modified: modules/statistics/tests/unit_tests/cdfpoi.dia.ref # modified: modules/statistics/tests/unit_tests/cdfpoi.tst # no changes added to commit (use "git add" and/or "git commit -a") myname@MYMACHINE /f/mygitrepository/scilab/scilab (master) $ myname@MYMACHINE /f/mygitrepository/scilab/scilab (master) $ git add CHANGES_5.3.X myname@MYMACHINE /f/mygitrepository/scilab/scilab (master) $ git add RELEASE_NOTES_5.3.X myname@MYMACHINE /f/mygitrepository/scilab/scilab (master) $ git add modules/statistics/src/dcdflib/cdfbet.f [...] myname@MYMACHINE /f/mygitrepository/scilab/scilab (master) $ git add modules/statistics/tests/unit_tests/cdfpoi.tst myname@MYMACHINE /f/mygitrepository/scilab/scilab (master) $ git status # On branch master # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # modified: CHANGES_5.3.X # modified: RELEASE_NOTES_5.3.X # modified: modules/statistics/src/dcdflib/cdfbet.f # modified: modules/statistics/src/dcdflib/cdfbin.f # modified: modules/statistics/src/dcdflib/cdfchi.f [...] # modified: modules/statistics/tests/unit_tests/cdfpoi.dia.ref # modified: modules/statistics/tests/unit_tests/cdfpoi.tst # myname@MYMACHINE /f/mygitrepository/scilab/scilab (master) $ git commit -m "statistics: Bug #7569: increased accuracy of inversion of several CDF" [master bb7b3e2] statistics: Bug #7569: increased accuracy of inversion of several CDF 18 files changed, 1145 insertions(+), 196 deletions(-) rewrite scilab/modules/statistics/tests/unit_tests/cdfgam.dia.ref (98%) rewrite scilab/modules/statistics/tests/unit_tests/cdfgam.tst (98%) rewrite scilab/modules/statistics/tests/unit_tests/cdfnor.dia.ref (99%) rewrite scilab/modules/statistics/tests/unit_tests/cdfnor.tst (98%) rewrite scilab/modules/statistics/tests/unit_tests/cdfpoi.dia.ref (99%) rewrite scilab/modules/statistics/tests/unit_tests/cdfpoi.tst (98%)
Push the commit, after getting the updates
myname@MYMACHINE /f/mygitrepository/scilab/scilab (master) $ git fetch Enter passphrase for key '/c/Users/myname/.ssh/id_rsa': remote: Counting objects: 35646, done remote: Compressing objects: 100% (661/661) Receiving objects: 100% (661/661), 197.07 KiB, done. Resolving deltas: 100% (389/389), completed with 201 local objects. From ssh://git.scilab.org:29418/scilab c1c5f77..b988e59 YaSp -> origin/YaSp 56ab43a..137226e graphic -> origin/graphic 9a8d90d..86c529c javasci-v2 -> origin/javasci-v2 eb2b520..a1806f9 master -> origin/master myname@MYMACHINE /f/mygitrepository/scilab/scilab (master) $ git rebase origin/master master First, rewinding head to replay your work on top of it... Applying: statistics: Bug #7569: increased accuracy of inversion of several CDF myname@MYMACHINE /f/mygitrepository/scilab/scilab (master) $ git push Enter passphrase for key '/c/Users/myname/.ssh/id_rsa': Counting objects: 53, done. Delta compression using up to 4 threads. Compressing objects: 100% (27/27), done. Writing objects: 100% (27/27), 8.07 KiB, done. Total 27 (delta 24), reused 0 (delta 0) remote: (W) 9fd425: commit subject >65 characters; use shorter first paragraph remote: remote: New Changes: remote: http://codereview.scilab.org/1921 remote: To ssh://myfirstname.myname@git.scilab.org:29418/scilab * [new branch] master -> refs/for/master
Getting clean
myname@MYMACHINE /f/mygitrepository/scilab/scilab (master) $ git status # On branch master # Your branch is ahead of 'origin/master' by 1 commit. # nothing to commit (working directory clean) myname@MYMACHINE /f/mygitrepository/scilab/scilab (master) $ git reset --hard remotes/origin/master HEAD is now at a1806f9 Bad merge in codereviewx 1808 myname@MYMACHINE /f/mygitrepository/scilab/scilab (master) $ git status # On branch master nothing to commit (working directory clean)