Skip navigation.
Home

Git practices, workflows and tips

For a smoother migration from SVN to Git, a page was created, mapping most of the SVN commands to Git commands. The page can be found HERE.

For any issue with AliRoot Git repository please submit a ticket to Git adminstration Jira project.

  1. First time with Git and AliRoot

  2. Git workflows

    1. Basic concepts

    2. Development workflow

  3. Create and send a patch

    1. Create a patch

    2. Apply a patch

  4. Revert/reset commits

  5. Solve conflicts

  6. Change commit information

1. First time with Git And AliRoot

Git comes with a tool called "git config" that lets you get and set configuration variables that control all aspects of how Git looks and operates.

User specific configuration is stored in a ~/.gitconfig file located in your $HOME folder. You can make Git read and write to this file specifically by passing the --global option.

1. Your identity - Please set your CERN computing identity before committing to AliRoot repository.

Note that it is very important to set this information because the user.name is used by different systems such as Coverity or JIRA.

To set this information globally use the git config command below. This will set the author information for all your Git repositories.

$ git config --global user.name "YOUR_CERN_COMPUTING_ACCOUNT"
$ git config --global user.email "YOUR_EMAIL_LINKED_TO_CERN_COMPUTING_ACCOUNT"

If you have more than one repository that you are committing and you want to use different author information you can set it per repository by removing --global flag.

Please remember to set this information for all your working instances/computers.

2. Your editor - optional   

$ git config --global core.editor emacs

3. Your diff/merge tool - optional   

$ git config --global merge.tool vimdiff

    Git accepts kdiff3, tkdiff, meld, xxdiff, emerge, vimdiff, gvimdiff, ecmerge, and opendiff as valid merge tools.

4. Set Git to always rebase when pulling from a remote repository

$ git config --global branch.autosetuprebase always  (for all new branches
$ git config --global branch.master.rebase true  (for other existing branches, replace master with the branch you want to use)

If you do not want to rebase but you set it using git config you can use the command below to ignore rebasing

$ git pull --no-rebase

5. Push only the current branch you are working on

$ git config --global push.default simple

6. Color highlighting

$ git config --global color.ui true
$ git config --global color.status auto
$ git config --global color.branch auto

7. List the configuration

Global configuration.

$ git config --global --list

For local repository configuration remove --global flag.

For more information about how to further configure your git client please visit
http://git-scm.com/book/en/Customizing-Git-Git-Configuration

2. Git workflows

NOTE: The examples are using a AliRoot-clone repository, please remember to change it to AliRoot.

2.1 Basic concepts

The following examples will contain some Git basic concepts. Please read carefully all commands and comments.

The figure below describes the data flow inside a Git repository. The flow will be explained step by step.

First step is to clone the AliRoot repository. Git cloning is similar to checking out the full AliRoot SVN repository. The clone contains all branches and tags that currently exist in AliRoot.

$ git clone https://git.cern.ch/reps/AliRoot-clone
Cloning into 'AliRoot-clone'...
Username for 'https://git.cern.ch': agrigora
Password for 'https://agrigora@git.cern.ch':
remote: Counting objects: 444764, done.
remote: Compressing objects: 100% (101652/101652), done.
remote: Total 444764 (delta 340763), reused 444764 (delta 340763)
Receiving objects: 100% (444764/444764), 2.16 GiB | 22.53 MiB/s, done.
Resolving deltas: 100% (340763/340763), done.
Checking connectivity... done
Checking out files: 100% (19429/19429), done.

Next step is to go into the AliRoot repository folder.

For the bash console to display in the prompt the current checkout branch I used http://code-worrier.com/blog/git-branch-in-bash-prompt/

$ cd AliRoot-clone

The default checkout branch is master

~/AliRoot-clone (master)$ git status
# On branch master
nothing to commit, working directory clean

Making some changes to a file from the repository

~ AliRoot-clone (master)$ vi PWGGA/GammaConv/AliAnalysisTaskGammaConvV1.cxx

Checking the status of the repository

AliRoot-clone (master)$ git status
# On branch master
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#       modified:   PWGGA/GammaConv/AliAnalysisTaskGammaConvV1.cxx
#
no changes added to commit (use "git add" and/or "git commit -a")

The message above tells us that a file was modified but not added to the staging area/index, therefore it will not be committed ("no changes added to commit" message). The figure below explains how a file is staged and then committed.

We can see the difference between the working area and the staging area/index using the diff command:

AliRoot-clone (master)$ git diff
diff --git a/PWGGA/GammaConv/AliAnalysisTaskGammaConvV1.cxx b/PWGGA/GammaConv/AliAnalysisTaskGammaConvV1.cxx
index 26ff582..362645e 100644
--- a/PWGGA/GammaConv/AliAnalysisTaskGammaConvV1.cxx
+++ b/PWGGA/GammaConv/AliAnalysisTaskGammaConvV1.cxx
@@ -16,7 +16,8 @@
  * about the suitability of this software for any purpose. It is         *
  * provided "as is" without express or implied warranty.                         *
  **************************************************************************/
-
+//this is just a test line
+// this is the second test line
 ////////////////////////////////////////////////
 //---------------------------------------------

We are now ready to add the changes to the staging area/index.

AliRoot-clone (master)$ git add PWGGA/GammaConv/AliAnalysisTaskGammaConvV1.cxx

A 'git status' will show the following

AliRoot-clone (master)$ git status
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#       modified:   PWGGA/GammaConv/AliAnalysisTaskGammaConvV1.cxx
#

Now the file is ready to be committed. If you do extra changes to the file DO NOT FORGET to add it again to the staging area/index. A simple 'git diff' now will show no changes because there are no changes between my working space and the staging area.

AliRoot-clone (master)$ git diff

But we can see the changes between the staging area/index and the original file from the repository using the command bellow.

AliRoot-clone (master)$ git diff --cached
diff --git a/PWGGA/GammaConv/AliAnalysisTaskGammaConvV1.cxx b/PWGGA/GammaConv/AliAnalysisTaskGammaConvV1.cxx
index 26ff582..362645e 100644
--- a/PWGGA/GammaConv/AliAnalysisTaskGammaConvV1.cxx
+++ b/PWGGA/GammaConv/AliAnalysisTaskGammaConvV1.cxx
@@ -16,7 +16,8 @@
  * about the suitability of this software for any purpose. It is         *
  * provided "as is" without express or implied warranty.                         *
  **************************************************************************/
-
+//this is just a test line
+// this is the second test line
 ////////////////////////////////////////////////
 //---------------------------------------------
 

The next step is to commit the changes. You can use the -m flag to add a message or a simple commit will automatically open an editor for you to add your comment.

AliRoot-clone (master)$ git commit -m "Some test changes"
[master c7cac45] Some test changes
 1 file changed, 2 insertions(+), 1 deletion(-) 

A 'git status' will remind us that the local branch is ahead from the original pulled branch with one commit.

AliRoot-clone (master)$ git status
# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.
#   (use "git push" to publish your local commits)
#
nothing to commit, working directory clean

In order to see what changes are between your branch and the original pull you can use the command 'git diff
--name-status', which will print only the touched files and the operation on them:

AliRoot-clone (master)$ git diff --name-status origin/master 
M       PWGGA/GammaConv/AliAnalysisTaskGammaConvV1.cxx 

To check the full changes you can use again diff.

AliRoot-clone (master)$ git diff  origin/master
diff --git a/PWGGA/GammaConv/AliAnalysisTaskGammaConvV1.cxx b/PWGGA/GammaConv/AliAnalysisTaskGammaConvV1.cxx
index 26ff582..362645e 100644
--- a/PWGGA/GammaConv/AliAnalysisTaskGammaConvV1.cxx
+++ b/PWGGA/GammaConv/AliAnalysisTaskGammaConvV1.cxx
@@ -16,7 +16,8 @@
  * about the suitability of this software for any purpose. It is         *
	  * provided "as is" without express or implied warranty.                         *
  **************************************************************************
-
+//this is just a test line
+// this is the second test line
 ////////////////////////////////////////////////
 //--------------------------------------------- 

Git "diff" command can offer additional information about the changes inside your repository.  For more options you can use "git diff --help" or "man git diff"

Now we are ready to share our changes with the world. But first the repository needs to be updated to the latest snapshot from the central repository.

AliRoot-clone (master)$ git pull --rebase
Username for 'https://git.cern.ch': agrigora
Password for 'https://agrigora@git.cern.ch':
Current branch master is up to date.

Pushing the changes to the central repository

AliRoot-clone (master)$ git push origin master
Username for 'https://git.cern.ch': agrigora
Password for 'https://agrigora@git.cern.ch': 
Counting objects: 9, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (5/5), done.
Writing objects: 100% (5/5), 497 bytes | 0 bytes/s, done.
Total 5 (delta 4), reused 0 (delta 0)
To https://git.cern.ch/reps/AliRoot-clone
   2282bc7..c7cac45  master -> master

2.2 Development workflow

Before reading about the possible workflows please visit the Basic concepts section.

The proposed workflow is based on Fast Forward Merge, so before reading further please take a look at this "picture" explaining the basic concept.

The examples below are always asking for CERN credentials, but do not forget that credentials can be cached. In order to achieve this please follow the instruction from the SVN to Git page

Let's say we are in a synchronized working area, the local master is the same as the central remote master, following a:

AliRoot-clone (master)$ git pull --rebase
Username for 'https://git.cern.ch': agrigora
Password for 'https://agrigora@git.cern.ch': 
Current branch master is up to date.

Git status will report

AliRoot-clone (master)$ git status
# On branch master
nothing to commit, working directory clean

The proposed workflow:
- Create a branch off Master
- Do work
- Merge it back into Master when done

The workflow above translates in the following commands.

1. Create the new branch from the current master and switch to it

AliRoot-clone (master)$ git checkout -b master_bug12345
Switched to a new branch 'master_bug12345'
AliRoot-clone (master_bug12345)$ 

"git checkout -b" is a shortcut for "git branch master_bug12345 && git checkout master_bug12345"

2. Do your changes

AliRoot-clone (master_bug12345)$ emacs STEER/SetDefaultCuts.C

3. Add the file to the staging/index area

AliRoot-clone (master_bug12345)$ git add STEER/SetDefaultCuts.C

4. Commit your changes

AliRoot-clone (master_bug12345)$ git commit -m "Fixing bug 12345"
[master_bug12345 aacd409] Fixing bug 12345
 1 file changed, 2 insertions(+)

When committing the changes you can set a message using the -m flag. Removing -m flag will open an editor asking you to set a commit message.
The commit message is split in 2 sections:
Capitalized, short (50 chars or less) summary

--------- Note the blank line above--------
More detailed explanatory text, if necessary. Wrap it to about 72 characters or so. In some contexts, the first line is treated as the subject of an email and the rest of the text as the body. The blank line separating the summary from the body is critical (unless you omit the body entirely); tools like rebase can get confused if you run the two together.

The summary is the text that appears in basic listings, so it should properly summarize the commit.

5. Merge your branch to the master

AliRoot-clone (master_bug12345)$ git checkout master
Switched to branch 'master'
AliRoot-clone (master)$ 
liRoot-clone (master)$ git merge master_bug12345
Updating c7cac45..aacd409
Fast-forward
 STEER/SetDefaultCuts.C | 2 ++
 1 file changed, 2 insertions(+)

6. Push your changes to the central repository

Before any push your local repository has to be synchronized with the central repository. The pull might bring changes that were done by other developers.

AliRoot-clone (master)$ git pull --rebase
Username for 'https://git.cern.ch': agrigora
Password for 'https://agrigora@git.cern.ch': 
remote: Counting objects: 5, done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 3 (delta 2), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
From https://git.cern.ch/reps/AliRoot-clone
   c7cac45..2b3afe7  master     -> origin/master
First, rewinding head to replay your work on top of it...
Applying: Fixing bug 12345

Now we can push, of course if another user is faster you need to redo the pull --rebase

 

AliRoot-clone (master)$ git push origin master
Username for 'https://git.cern.ch': agrigora
Password for 'https://agrigora@git.cern.ch': 
Counting objects: 7, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (4/4), 384 bytes | 0 bytes/s, done.
Total 4 (delta 3), reused 0 (delta 0)
To https://git.cern.ch/reps/AliRoot-clone
   2b3afe7..975c320  master -> master

 

Now you either delete the branch or continue to develop inside it after rebasing it to the master

AliRoot-clone (master)$ git checkout master_bug12345
Switched to branch 'master_bug12345'
AliRoot-clone (master_bug12345)$ git rebase master
First, rewinding head to replay your work on top of it...
AliRoot-clone (master_bug12345)$ git diff master
AliRoot-clone (master_bug12345)$  //no change between your local branch or master

Or just delete it and start from the beginning

AliRoot-clone (master_bug12345)$ git checkout master
Switched to branch 'master'
AliRoot-clone (master)$ git branch -d master_bug12345
Deleted branch master_bug12345 (was 975c320).

 

3. Create and send a patch

AliRoot repository has power users that are allowed to commit changes on behalf of other developers. 

The developers that do not have push rights to AliRoot repository have to send patches to the power users to be committed and pushed.

3.1 How to create a patch

Even if the developer has no push rights he/she should follow the proposed workflow from above.

AliRoot-clone (master)$ git checkout -b master_patch
Switched to a new branch 'master_patch'
AliRoot-clone (master_patch)$ emacs PWGJE/AliFragmentationFunctionCorrections.cxx
AliRoot-clone (master_patch)$ emacs PWGJE/AliPWG4HighPtSpectra.cxx
AliRoot-clone (master_patch)$ git add PWGJE/AliFragmentationFunctionCorrections.cxx PWGJE/AliPWG4HighPtSpectra.cxx
AliRoot-clone (master_patch)$ git commit -m "Testing the patch"
[master_patch bf01859] Testing the patch
 2 files changed, 5 insertions(+), 1 deletion(-)

It is possible to check the list of commits that are in master_patch branch but not in master (for a simpler format add the flag --pretty=oneline)

AliRoot-clone (master_patch)$ git log master_patch ^master 
commit 429378aa00f932cdf6c94ad4e07e826574d1c979
Author: agrigora alina.gabriela.grigoras@cern.ch
Date:   Wed Feb 12 16:04:47 2014 +0100

    Another test for patching

commit bf018598685193741c1d3fa8683a07d15ed99043
Author: agrigora alina.gabriela.grigoras@cern.ch
Date:   Wed Feb 12 15:52:46 2014 +0100

    Testing the patch

The next step is to create the patch

AliRoot-clone (master_patch)$ git format-patch master --stdout > /tmp/MyPatch.patch

That's it! Send the patch by email to the super user that is allowed to push your changes

3.2 How to apply the received patch

First, take a look at what changes are in the patch. You can do this easily with git apply

AliRoot-clone (master)$ git apply --stat /tmp/MyPatch.patch
 PWGJE/AliFragmentationFunctionCorrections.cxx |    4 +++-
 PWGJE/AliPWG4HighPtSpectra.cxx                |    2 ++
 PWGJE/AliPWG4HighPtSpectra.cxx                |    2 +-

Note that this command does not apply the patch, but only shows you the stats about what it’ll do.

Next, you’re interested if the patch can be applied.

AliRoot-clone (master)$ git apply --check /tmp/MyPatch.patch

You can use git apply some.patch to have the changes from the .patch file applied to your current working directory. They will be unstaged and need to be committed by you.

To apply a patch as a commit (with its commit message), use git am some.patch.

AliRoot-clone (master)$ git apply  /tmp/MyPatch.patch
/tmp/MyPatch.patch:20: trailing whitespace.
    for(int i=0; i<fArraySize; i++) delete fh1CorrFFXi[i];  
/tmp/MyPatch.patch:21: trailing whitespace.
    // 1. doing something here        
warning: 2 lines add whitespace errors.
AliRoot-clone (master)$ git status
# On branch master
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#       modified:   PWGJE/AliFragmentationFunctionCorrections.cxx
#       modified:   PWGJE/AliPWG4HighPtSpectra.cxx
##

The changes were applied to your working directory but you need to commit them. This applies in cases that the code is not sure and it might need changes.

In case you are sure the received code is correct you can apply directly the patch as a commit

AliRoot-clone (master)$ git am --ignore-whitespace  /tmp/MyPatch.patch
AliRoot-clone (master)$ git log --pretty=oneline 
1535e436441306e5168fa0d04af461f976add790 Another test for patching
0c4c2f94805c4dd2fe2f7c2c43e9779139a8d3d4 Testing the patch

4. Revert/reset commits

In case you are not satisfied with the changes done to your source code there is the option to undo the changes.

The operation to undo the changes depends on the state of your repository.

1. The changes are only in your working area, they were not added to the staging area with "git add " command.

A git status command will show

AliRoot-clone (master_undo)$ git status
# On branch master_undo
# Changes not staged for commit:
#   (use "git add ..." to update what will be committed)       
#   (use "git checkout -- ..." to discard changes in working directory)
#                                                                   
#       modified:   README_CMake                                    
#                               
no changes added to commit (use "git add" and/or "git commit -a")

As the "git status" output is mentioning you can remove the changes by running.

AliRoot-clone (master_undo)$ git checkout -- README_CMake

A "git status" will show there are no changes in our working space

AliRoot-clone (master_undo)$ git status                                                              
# On branch master_undo                                  
nothing to commit, working directory clean 

2. The changes were added to the staging/index area

A git status would report

AliRoot-clone (master_undo)$ git status                                                              
# On branch master_undo                                                                             
# Changes to be committed:                                                                          
#   (use "git reset HEAD ..." to unstage)                                                     
#
#       modified:   README_CMake
#

Again git verbose message suggests us what to do with the file if we want to revert changes. If we want to unstage the changes, but keep them in our working directory we follow the command above

AliRoot-clone (master_undo)$ git reset HEAD README_CMake
Unstaged changes after reset:
M       README_CMake
AliRoot-clone (master_undo)$ git status
# On branch master_undo
# Changes not staged for commit:
#   (use "git add ..." to update what will be committed)
#   (use "git checkout -- ..." to discard changes in working directory)
#
#       modified:   README_CMake
#
no changes added to commit (use "git add" and/or "git commit -a")

If we do not want to keep any changes than we use the checkout command slightly modified

AliRoot-clone (master_undo)$ git checkout HEAD README_CMake
AliRoot-clone (master_undo)$ git status
# On branch master_undo
nothing to commit, working directory clean

3. The changes were committed to the local repository

In this case Git gives 2 option, to revert the changes or to reset them

Revert command creates a new commit that undoes the changes from a previous commit. This command adds new history to the project (it doesn't modify existing history).

Reset command actually can delete commits and change history

AliRoot-clone (master_undo)$ git log --pretty=oneline -3
19e6c0b53d44fa36eae004151636c030db920bee Test commit for revert/reset
d2233de7725246e17ea79b96b2a08c83a938c6c2 Adding another commit
975c320075b4a7dca59581ee2fab1acfd225b59c Fixing bug 12345

Let's try to revert the changes, we do not care about the extra commit

AliRoot-clone (master_undo)$ git revert 19e6c0b53d44fa36eae004151636c030db920bee
[master_undo 8cbe723] Revert "Test commit for revert/reset"
 1 file changed, 1 deletion(-)
AliRoot-clone (master_undo)$ git log --pretty=oneline -3
8cbe7233a427ee2c17744ddda9fbb75b0542339b Revert "Test commit for revert/reset"
19e6c0b53d44fa36eae004151636c030db920bee Test commit for revert/reset
d2233de7725246e17ea79b96b2a08c83a938c6c2 Adding another commit

The changes were undone and a new commit was added to the history

Let's try to use now reset. As usual Git gives more options, you can either reset the file to the working area, which is called soft reset, or you can completely wipe the commit

AliRoot-clone (master_undo)$ git reset d2233de7725246e17ea79b96b2a08c83a938c6c2
Unstaged changes after reset:
M       README_CMake
AliRoot-clone (master_undo)$ git status
# On branch master_undo
# Changes not staged for commit:
#   (use "git add ..." to update what will be committed)
#   (use "git checkout -- ..." to discard changes in working directory)
#
#       modified:   README_CMake
#
no changes added to commit (use "git add" and/or "git commit -a")
AliRoot-clone (master_undo)$ git log --pretty=oneline -3
d2233de7725246e17ea79b96b2a08c83a938c6c2 Adding another commit
975c320075b4a7dca59581ee2fab1acfd225b59c Fixing bug 12345

Note that I reseted to the last commit just before my commit. You can also reset last commit using "git reset --soft HEAD^". Add ^ for last 2, 3 and so on

If you want to wipe the commit and loose all changes you can use the hard reset

AliRoot-clone (master_undo)$ git log --pretty=oneline -3
c33d1a9a95e5ba09123006ceb11a6c5f25fd2eff Test commit for revert/reset
d2233de7725246e17ea79b96b2a08c83a938c6c2 Adding another commit
975c320075b4a7dca59581ee2fab1acfd225b59c Fixing bug 12345
AliRoot-clone (master_undo)$ git reset --hard HEAD^
HEAD is now at d2233de Adding another commit
alinag@pcepalice49:/tmp/AliRoot-clone (master_undo)$ git log --pretty=oneline -3
d2233de7725246e17ea79b96b2a08c83a938c6c2 Adding another commit
975c320075b4a7dca59581ee2fab1acfd225b59c Fixing bug 12345
AliRoot-clone (master_undo)$ git status
# On branch master_undo
nothing to commit, working directory clean

5. Solve conflicts

After a pull --rebase we might get a conflict. A conflict message looks like below

AliRoot-clone2 (master)$ git pull --rebase
Username for 'https://git.cern.ch': agrigora
Password for 'https://agrigora@git.cern.ch': 
remote: Counting objects: 5, done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 3 (delta 2), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
From https://git.cern.ch/reps/AliRoot-clone
   4456829..89d0eec  master     -> origin/master
First, rewinding head to replay your work on top of it...
Applying: Our local conclict
Using index info to reconstruct a base tree...
M       README_CMake
Falling back to patching base and 3-way merge...
Auto-merging README_CMake
CONFLICT (content): Merge conflict in README_CMake
Failed to merge in the changes.
Patch failed at 0001 Our local conclict
The copy of the patch that failed is found in:
   /tmp/AliRoot-clone2/.git/rebase-apply/patch

When you have resolved this problem, run "git rebase --continue".
If you prefer to skip this patch, run "git rebase --skip" instead.
To check out the original branch and stop rebasing, run "git rebase --abort".

alinag@pcepalice49:/tmp/AliRoot-clone2 (master|REBASE 1/1)$ 

The log already offers 2 solutions, we either keep our version using --skip flag, or we accept the version from the remote central repository by using --abort. But we can investigate further using "mergetool". The merge tool requires to set a default merge tool or the use of -t flag to point to the chosen mergetool. Valid values include emerge, gvimdiff, kdiff3, meld, vimdiff, and tortoisemerge. Run git mergetool --tool-help for the list of valid <tool> settings. In the example below the default is set to kdiff3.

A Git status will show

AliRoot-clone (master|REBASE 1/1)$ git status
# HEAD detached at 6dc4c37
# You are currently rebasing branch 'master' on '6dc4c37'.
#   (fix conflicts and then run "git rebase --continue")
#   (use "git rebase --skip" to skip this patch)
#   (use "git rebase --abort" to check out the original branch)
#
# Unmerged paths:
#   (use "git reset HEAD ..." to unstage)
#   (use "git add ..." to mark resolution)
#
#       both modified:      README_CMake
#
no changes added to commit (use "git add" and/or "git commit -a"

We can see the patch that failed to be applied

(master|REBASE 1/1)$ cat /tmp/AliRoot-clone/.git/rebase-apply/patch
2c509f9f917b32fe80cb81ab62a811fd0c894ad6
diff --git a/README_CMake b/README_CMake
index f6d3ffbd336f68b038cb50f7fa3c655a041771e5..83d2e8bfde40e5a5ced7d5852e5e7c8c53e7e423 100644
--- a/README_CMake
+++ b/README_CMake
@@ -1,4 +1,4 @@
-CONFLICT line 1 - Here we gonna have a conflict, try to fix
+CONFLICT line 1 - Here we gonna have a conflict, second line
 Just to test
 Note: The CMake build of AliRoot builds out-of-source

Or use git mergetool to see the conflict

AliRoot-clone2 (master|REBASE 1/1)$ git mergetool

The next step is to edit the file, solve the conflict and push the changes back

AliRoot-clone (master|REBASE 1/1)$ vi README_CMake
AliRoot-clone (master|REBASE 1/1)$ git status
# HEAD detached at 8cf5ac8
# You are currently rebasing branch 'master' on '8cf5ac8'.
#   (fix conflicts and then run "git rebase --continue")
#   (use "git rebase --skip" to skip this patch)
#   (use "git rebase --abort" to check out the original branch)
#
# Unmerged paths:
#   (use "git reset HEAD ..." to unstage)
#   (use "git add ..." to mark resolution)
#
#       both modified:      README_CMake
#
no changes added to commit (use "git add" and/or "git commit -a")
AliRoot-clone (master|REBASE 1/1)$ git add README_CMake
AliRoot-clone (master|REBASE 1/1)$ git rebase --continue
AliRoot-clone (master)$ git status
# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.
#   (use "git push" to publish your local commits)
#
nothing to commit, working directory clean
liRoot-clone (master)$ git push

6. Change commit information

 

All pushes containing commits with an author that it is not a CERN account will be rejected. This is not a stopper, it is possible to change author information after the changes were already committed.

The command used is interactive rebase.

Such a push will give the following error, complaining about the wrong username.

AliRoot-clone (master)$ git push origin master
Username for 'https://git.cern.ch': agrigora
Password for 'https://agrigora@git.cern.ch': 
Counting objects: 17, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (12/12), done.
Writing objects: 100% (12/12), 1.18 KiB | 0 bytes/s, done.
Total 12 (delta 9), reused 0 (delta 0)
remote: 
remote: You are trying to push commit 01480df5d21373c100ba7f2e55b32813da47e207: Testing CERN credentials
remote: Commiter: Alina Grigoras 
remote: Author: Alina Grigoras 
remote: All your commits have to have a CERN computing account author: CERN_COMPUTING_ACCOUT 
remote: Note: you will need to change the commiter name in your current commits too.
remote: See http://stackoverflow.com/questions/3042437/change-commit-author-at-one-specific-commit
remote: 
To https://git.cern.ch/reps/AliRoot-clone
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.cern.ch/reps/AliRoot-clone'

First you need to set correctly user.name and user.email configuration. After fixing these 2 parameters you can go on with changing author information.

Check using git log which commits have the wrong information:

AliRoot-clone (master)$ git log --format="%an %H"
Alina Grigoras 01480df5d21373c100ba7f2e55b32813da47e207
agrigora 1535e436441306e5168fa0d04af461f976add790

Enter in rebase mode with the commit just before the commit you want to change the author

AliRoot-clone (master)$ git rebase -i 1535e436441306e5168fa0d04af461f976add790
pick 01480df Testing CERN credentials

# Rebase 1535e43..01480df onto 1535e43
#
# Commands:
#  p, pick = use commit
#  r, reword = use commit, but edit the commit message
#  e, edit = use commit, but stop for amending
#  s, squash = use commit, but meld into previous commit
#  f, fixup = like "squash", but discard this commit's log message
#  x, exec = run command (the rest of the line) using shell
#
# These lines can be re-ordered; they are executed from top to bottom.
#
# If you remove a line here THAT COMMIT WILL BE LOST.
#
# However, if you remove everything, the rebase will be aborted.
#
# Note that empty commits are commented out

Change pick to edit, save and exit. Then continue in interactive rebase to change the author information.

AliRoot-clone (master)$ git rebase -i 1535e436441306e5168fa0d04af461f976add790
Stopped at 01480df... Testing CERN credentials
You can amend the commit now, with

        git commit --amend

Once you are satisfied with your changes, run

        git rebase --continue

AliRoot-clone (master|REBASE-i 1/1)$ git commit --amend --author="agrigora <alina.gabriela.grigoras@cern.ch>"
[detached HEAD 3f74e2a] Testing CERN credentials
 Author: agrigora 
 1 file changed, 1 insertion(+)
AliRoot-clone (master|REBASE-i 1/1)$ git rebase --continue
AliRoot-clone (master)$ git log --format="%an %H" 
agrigora 3f74e2ab05c82cb50e89e2e906a632b1fb2b3315
agrigora 1535e436441306e5168fa0d04af461f976add790