FAQ Recuperar, actualizar GIT fuentes del proyecto: Difference between revisions

From Dolibarr ERP CRM Wiki
Jump to navigation Jump to search
No edit summary
Line 2: Line 2:
{{TemplateDocDevEs}}
{{TemplateDocDevEs}}


Esta es información sobre cómo puede obtener los fuentes del proyecto Dolibarr. Este tutorial explica los pasos a seguir utilizando el IDE Eclipse.
{{ToTranslate}}
This is informations on how you can get sources of Dolibarr project.


= Prerrequisitos =
=Get last version of sources by download=
En primer lugar debe tener funcionando una instalación de Eclipse. También debe tener instalado el plugin '''EGit'''.
This method allows you to get sources of main development branch (called HEAD): This operation consist to get last version of Dolibarr files that are packaged each night into a tgz file.
Para ello, use la opción '''Find And Install process''' en los menús de Eclipse, añada la url de actualización de GIT:
For this, go on page with [http://www.dolibarr.org/downloads/cat_view/64-development-version last source version of the day].


http://download.eclipse.org/egit/updates
New files overwrite old ones.
The inconvenient of this method is that you must download and uncompress package each time you want to get updates.


A continuación, seleccione la instalación de '''EGit'''.
=Get last version of sources using a GIT anonymous access=
== Prerequisite ==
First you must have a working install of Eclipse. '''EGit''' plugin must also have been installed.
For this, use the '''Find And Install process''' into Eclipse menu, add the GIT update URL:
http://download.eclipse.org/egit/updates
Then choose to install '''EGit'''.


=Obtener la última versión de los fuentes usando un acceso GIT anónimo=
To get sources with goal to edit them, you need a GitHub write access to the GIT remote repository, and a GIT client (GIT command line tool with Linux, or the GIT client in Eclipse). See next chapter for this.


Para obtener los fuentes con el propósito de editarlos, necesita un acceso GitHub en escritura al repositorio remoto GIT y un cliente GIT (Comando GIT en linux o el Cliente GIT en Eclipse).
First, enter value of the repository with reference sources into your GIT client tool.


En primer lugar, hay que introducir el repositorio de referencia que contiene los fuentes en su cliente GIT
* With Eclipse, choose "Clone GIT repository". Enter GIT URL of project to get.
Con Eclipse, seleccione "Clone GIT repository". Introduzca la URL GIT del proyecto a obtener.
GIT Url for Dolibarr official source is:
La URL GIT de los fuentes oficiales Dolibarr es:
<source lang="ini">
<source lang="ini">
git://github.com/Dolibarr/dolibarr.git
git://github.com/Dolibarr/dolibarr.git
</source>
</source>
Your Eclipse GIT client will ask you to choose the branches you are interesting in. Branches not selected now could be selected later by doing a "Fetch" from the "Remotes" view, but try to choose only the branch you need. This will save you time and problems later.


Su cliente GIT le preguntará por las ramas en las que esté interesado. Las ramas no seleccionadas podrán seleccionarse después con un "Fetch" desde la vista "Remotes", así que trate de elegir sólo la rama que necesita. Esto le ahorrará tiempo y problemas en el futuro.  
* With GIT on Command Line Interface:
First setup your git client:
<source lang="bash">
git config --global user.name "Your Name"
git config --global user.email "user@domain.com"
git config --list
</source>
Then clone repository locally:
<source lang="bash">
git clone git://github.com/Dolibarr/dolibarr.git dolibarr
</source>
And, if you are behind a firewall, you can user the alternate URL:
<source lang="bash">
git config --global http.proxy http://proxyuser:proxypass@proxyserver:proxyport
git clone https://gitlogin:gitpassword@github.com/Dolibarr/dolibarr.git dolibarr
</source>
 
Once this step is validated, your GIT client will download all files from remote GIT server. This may last several seconds or minutes.
 
Once download is finished, go into GIT view - Branches - Local. In most cases, the branch you choosed should be already available.
 
If not:
* With Eclipse, right click on "Branches - Remotes - The branch you want to duplicate locally".
If you choose "Create Branch", this will duplicate content of branch to work on it locally.
If you Choose "Checkout", this will update the view "Working Directory".
* With GIT on Command Line Interface;
<source lang="bash">
git checkout develop
git checkout x.y
</source>
This will create local branch and make checkout automatically.
 
 
If using Eclipse, once your branch is created locally, create a PHP project from assistant by choosing "'''Create from existing project'''" and select directory that is your GIT local repository (Do not choose to create a PHP project from scratch).
Then right click on project from your Eclipse workspace and Choose "'''Team - Share'''". Select GIT and click on option "'''Use or create repository in parent folder of project'''".
An alternate method is File->Import, Git->Project from Git, Select the Git repository and Next, Use New project Wizard -> Php project, enter the folder of you GIT local repository.
 
 
Then, you can setup Eclipse to avoid it to scan all project files for its build tools (Outline scanner, TODO scanner, syntax scanner...). This will avoid Eclipse to be too slow. For this, right click on project, choose Build Path and setup it like into following screenshot.


Una vez realizado este paso, su cliente GIT descargará todos los archivos desde el servidor remoto GIT. Esto puede durar varios segundos o minutos.
[[File:Eclipse php build path.png|240px]]
Una vez haya finalizado la descarga, vaya a la vista GIT - Branches - Local. En la mayoría de los casos, la rama seleccionada debe estar ya disponible.
De lo contrario, haga clic con el botón derecho en "Branches - Remotes - La rama que desea duplicar localmente".
Si elige "Create Branch", duplicará el contenido de la rama para trabajar en local.
Si elige "Checkout", actualizará la vista "Working Directory".


Una vez que su rama haya sido creada localmente, cree un proyecto PHP con el asistente Eclipse, eligiendo "'''Create from existing project'''" y seleccionando el directorio donde se encuentra su repositorio local GIT (No escoja crear un proyecto PHP desde cero).
=Get last version of sources using a full GIT access=
== Prerequisite ==
First you must have a working install of Eclipse. '''EGit''' plugin must also have been installed.
For this, use the '''Find And Install process''' into Eclipse menu, add the GIT update URL:
http://download.eclipse.org/egit/updates
Then choose to install '''EGit'''.


Seguidamente haga clic con el botón derecho del ratón sobre el proyecto del workspace de su Eclipse y escoja "'''Team - Share'''". Seleccione GIT y haga clic en la opción "'''Use or create repository in parent folder of project'''".
You must before create an account on GitHub (https://github.com/) and upload a public RSA or DSA certificate into your account profile.


=Obtener la última versión de los fuentes usando un acceso GIT completo=
Then process is same than getting sources with anonymous access.
El proceso es el mismo que el descrito para el acceso anónimo.
Sin embargo, antes debe crearse una cuenta en GitHub (https://github.com/) y subir un certificado RSA o DSA público RSA o DSA a su perfil de cuenta


La URL a usar para clonar GIT es la misma:
URL to use for GIT clone is same:
<source lang="ini">
<source lang="ini">
git@github.com:Dolibarr/dolibarr.git
git@github.com:Dolibarr/dolibarr.git
</source>
</source>


Tenga en cuenta que hay disponible una URL HTTP, aunque a veces está fuera de línea:
Note that a HTTP URL is also available but it's sometimes offline (so use first one instead):
<source lang="ini">
<source lang="ini">
https://yourgitlogin@github.com/Dolibarr/dolibarr.git
https://yourgitlogin@github.com/Dolibarr/dolibarr.git
</source>
</source>


=Actualizar su repositorio=
=Update your repository=
Para actualizar su workspace local, haga clic con el botón derecho en el proyecto de Eclipse y seleccione "Pull".
To update your local workspace, right click on Eclipse project and select "Pull".
Si ha realizado cambios en su workspace local en archivos que han cambiado en el GIT remoto, su cliente GIT realizará automáticamente un merge y marcará todos los archivos con conflictos como "conflict" (Mire más abajo para solucionarlo). Si no, usted recibirá todos los archivos de la nueva versión con los cambios incluidos.
 
If you made some changes into your Eclipse workspace on files that were changed into the GIT remote reference, your GIT client will make a merge automatically.
* If there is conflicts, the merge will mark all conflict files as "conflict" (See later to solve this state).
* If not, you will get all new version files including all your changes.
 
If you already have commited some files into your local repository, your workspace will be marked as "Merged".
All you have to do is make a commit to validate your local repository as including your changes and changes made by others.
 
= Commit and publish your changes =
To see all changes you made into your working directory and waiting to be added into Git:
* With GIT Command Line Interface:
<source lang="bash">
git status
git diff subdir/filename
</source>
 
To add changes made into your local repository into the GIT index, then commit this index :
* With Eclipse: Right click on file or directory to commit. Select file to add/remove/update into commit.
* With GIT Command Line Interface:
<source lang="bash">
git commit -a -m "Commit text"
</source>
This will save add and changes into your local branch.


=Comitear y publicar sus cambios=
To push them on the GIT repository server,
Para comitear los cambios realizados en su repositorio local, haga clic con el botón derecho del ratón en el archivo o directorio a comitear. Los cambios serán validados en su repositorio local.
* With Eclipse: right click on project and choose "'''Team - Push to Upstream'''".
* With GIT Command Line Interface:
<source lang="bash">
git push
</source>


Para subirlos al repositorio remoto GIT, haga clic con el botón derecho en el proyecto y escoja "'''Team - Push to Upstream'''".
To cancel a commit:
* With GIT Command Line Interface:
<source lang="bash">
git revert IdCommit  or  git revert HEAD  (for last commit)
</source>


= Añadir commits externos en su repositorio =
= Add an external commit into current repository =
Algunos desarrolladores pueden trabajar y comitearr en su propio repositorio Git después del fork del proyecto. Si está interesado en obtener esos cambios, Puede seguir los siguientes pasos con Eclipse:
Some developers may work and do commit into their own Git repository after forking the project. If you are interesting into getting this changes, you can import them with the following steps with Eclipse:
* En primer lugar, vaya a la vista de configuración de GIT y haga clic con el botón derecho en "'''Remotes'''" en su workspace de Eclipse y elija "'''Create a remote...'''"
* First, go into GIT setup view and right click on "'''Remotes'''" of your Eclipse Git working space and choose "'''Create a remote...'''"
* Indique el nombre o el fork remoto que el desarrollador ha creado (en la mayoría de casos es el login Git del desarrollador). Por ejemplo: "'''thedevlogin'''". Elija también "'''Configure Fetch'''".
* Type name or remote fork the developer has create (in most cases, it's developer Git login). For example: "'''thedevlogin'''". Choose also "'''Configure Fetch'''".
* Indique la URL del repositorio Git del desarrollador. Por ejemplo: '''git://github.com/thedevlogin/dolibarr.git'''. También añada el valor refspec para indicar la rama que desea obtener. Por ejemplo: '''refs/heads/master:refs/remotes/thedevlogin/master'''. Haga clic en "'''Save and Fetch'''". Se añadirá una nueva entrada en "Remote Tracking" que hará posible la lectura y obtención de los commits realizados en esa rama.
* Type URI of Git repository of developer. For example: '''git://github.com/thedevlogin/dolibarr.git'''. Also add a refspec value to declare the branch you want to get. For example: '''refs/heads/master:refs/remotes/thedevlogin/master'''. Click "'''Save and Fetch'''". A new entry will be added into "Remote Tracking" making possible to read/get commits done into this branch.


Ahora, vaya a la línea de comandos en su repositorio git (en muchos casos en Linux, es '''/home/yourlogin/git/yourdolibarr''') y teclee el comando cherry-pick git:
Now, go on command line of your git repository (in most cases on Linux, it's '''/home/yourlogin/git/yourdolibarr''') and type the git cherry-pick command:
<source lang="bash">
<source lang="bash">
git cherry-pick -x commitid
git cherry-pick -x commitid
</source>
</source>
donde el commitid es el valor del comit id que desea obtener.
where commitid is value of commit id you want to get.


Una vez hecho esto, vuelva a Eclipse y haga un refresh del proyecto. Verá que los archivos modificados aparecen con los decoradores (con los conflictos si hay).
Once this is done, go back to Eclipse and make a refresh on project. You will see modified files appears with decorators (with conflicts if there is).


=Solucionar conflictos=
=Solving a conflict=
Si un archivo ha sido marcado como "conflict" después de un Pull, abra el archivo para editarlo.
If a file has been marked as "conflict" after a Pull request, open the file to edit it.
Busque el string "<<<<<<<<<<", verá la parte de código que provoca el conflicto entre "<<<<<<<<<" y ">>>>>>>>". Edite las líneas de código manualmente y elimine "<<<<<<<<" y ">>>>>>>". Seguidamente, haga clic con en botón derecho del ratón en el fichero y seleccione "Add".
Find string "<<<<<<<<<<", you will see part of code that is conflict between "<<<<<<<<<" and ">>>>>>>>". Edit manually code lines and remove "<<<<<<<<" and ">>>>>>>".  
Si usted descartar por completo todos los cambios realizados en todos los archivos (restaurar su workspace con el contenido del repositorio remoto), haga clic con el botón derecho del ratón en el proyecto y seleccione "'''Reset'''", seguidamente "'''Hard'''" y "'''Reference - HEAD'''".  
 
Then, right click on file and select "Add".
 
If you prefer to forget completely all changes you made into all files (so to restore you workspace with content of remote repository), you can make a hard reset:
* With Eclipse, right click on project top line and select "'''Reset'''" then "'''Hard'''" then "'''Reference - HEAD'''".
* Using GIT command line tool, you can achieve this with command
<source lang="bash">
git reset --hard HEAD
</source>
 
=Tagging sources=
To add a tag to a current version:
<source lang="bash">
git tag -m "Tag for x.y.z_YYYYMMDD" "x.y.z_YYYYMMDD"
git push --tags
</source>


=Creating a new branch=
This is command used to start a new branch from a clean develop cloned repository:
<source lang="bash">
git branch x.y
git push origin x.y
</source>


=Statistics=
To count number of changes developers have made between a version x and y:
* First, run git merge-base to know the id of last common commit between x and y
<source lang="bash">
git merge-base origin/3.1 origin/develop
</source>
* Then run git log to have list of all changes from last common commit to last commit
<source lang="bash">
git log id_found_at_previous_step..HEAD
</source>
* To get total number of added/deleted lines:
<source lang="bash">
git log --ancestry-path --numstat --pretty="%H" id_found_at_previous_step..HEAD | awk 'NF==3 {plus+=$1; minus+=$2} END {printf("+%d, -%d\n", plus, minus)}'
</source>


Disponible más información sobre el uso de GIT [http://wiki.eclipse.org/EGit/User_Guide aquí].


=Obtener la última versión de los fuentes por descarga=
To count number of changes finally between a version x and y (it differs from previous count because in previous count, a change can be done 2 times at two different moment to change differently. With second method, you count change finally found if changes were ok at first try):
* Use same method than previously but instead of running git log, run git diff.
<source lang="bash">
git diff -b -M --numstat --pretty="%H" id_found_at_previous_step..HEAD | awk 'NF==3 {plus+=$1; minus+=$2} END {printf("+%d, -%d\n", plus, minus)}'
</source>


Este método le permite obtener las fuentes de la rama principal de desarrollo (llamada HEAD): Consiste en obtener la última versión de los archivos de Dolibarr que se empaquetan cada noche en un archivo tgz.
Vaya a la página [http://www.dolibarr.org/downloads/cat_view/64-development-version last source version of the day].


Los archivos antiguos serán reemplazados por los nuevos.
More information in GIT usage is available [http://wiki.eclipse.org/EGit/User_Guide here].
El inconveniente de este método es que debe descargar y descomprimir los paquetes cada vez que desee obtener actualizaciones.

Revision as of 10:24, 16 May 2012

En verysmall.png Page waiting for translation. To translate, create an account, go back and clic on "Modify".
Fr verysmall.png Page en attente de traduction. Pour traduire, créez un compte, revenez et cliquez sur "Modifier".
Es verysmall.png Página a traducir. Para traducirla, cree una cuenta, vuelva a la página y haga clic en "editar".
It verysmall.png Pagina da tradurre. Per tradurla, crea un utente, torna indietro e clicca su "modifica".
Pt verysmall.png Página a aguardar por tradução. Para traduzir, crie uma conta, volte atrás e clique em "Modificar".
De verysmall.png Seite wartet auf Übersetzung. Um Übersetzung zu erstellen, richte einen Account ein, geh zurück und klicke auf "bearbeiten".
Zh verysmall.png 页面等待翻译。若要翻译本页,先创建一个帐户、登录并返回本页后单击“编辑”。

This is informations on how you can get sources of Dolibarr project.

Get last version of sources by download

This method allows you to get sources of main development branch (called HEAD): This operation consist to get last version of Dolibarr files that are packaged each night into a tgz file. For this, go on page with last source version of the day.

New files overwrite old ones. The inconvenient of this method is that you must download and uncompress package each time you want to get updates.

Get last version of sources using a GIT anonymous access

Prerequisite

First you must have a working install of Eclipse. EGit plugin must also have been installed. For this, use the Find And Install process into Eclipse menu, add the GIT update URL:

http://download.eclipse.org/egit/updates

Then choose to install EGit.

To get sources with goal to edit them, you need a GitHub write access to the GIT remote repository, and a GIT client (GIT command line tool with Linux, or the GIT client in Eclipse). See next chapter for this.

First, enter value of the repository with reference sources into your GIT client tool.

  • With Eclipse, choose "Clone GIT repository". Enter GIT URL of project to get.

GIT Url for Dolibarr official source is:

git://github.com/Dolibarr/dolibarr.git

Your Eclipse GIT client will ask you to choose the branches you are interesting in. Branches not selected now could be selected later by doing a "Fetch" from the "Remotes" view, but try to choose only the branch you need. This will save you time and problems later.

  • With GIT on Command Line Interface:

First setup your git client:

git config --global user.name "Your Name"
git config --global user.email "user@domain.com"
git config --list

Then clone repository locally:

git clone git://github.com/Dolibarr/dolibarr.git dolibarr

And, if you are behind a firewall, you can user the alternate URL:

git config --global http.proxy http://proxyuser:proxypass@proxyserver:proxyport
git clone https://gitlogin:gitpassword@github.com/Dolibarr/dolibarr.git dolibarr

Once this step is validated, your GIT client will download all files from remote GIT server. This may last several seconds or minutes.

Once download is finished, go into GIT view - Branches - Local. In most cases, the branch you choosed should be already available.

If not:

  • With Eclipse, right click on "Branches - Remotes - The branch you want to duplicate locally".

If you choose "Create Branch", this will duplicate content of branch to work on it locally. If you Choose "Checkout", this will update the view "Working Directory".

  • With GIT on Command Line Interface;
git checkout develop
git checkout x.y

This will create local branch and make checkout automatically.


If using Eclipse, once your branch is created locally, create a PHP project from assistant by choosing "Create from existing project" and select directory that is your GIT local repository (Do not choose to create a PHP project from scratch). Then right click on project from your Eclipse workspace and Choose "Team - Share". Select GIT and click on option "Use or create repository in parent folder of project". An alternate method is File->Import, Git->Project from Git, Select the Git repository and Next, Use New project Wizard -> Php project, enter the folder of you GIT local repository.


Then, you can setup Eclipse to avoid it to scan all project files for its build tools (Outline scanner, TODO scanner, syntax scanner...). This will avoid Eclipse to be too slow. For this, right click on project, choose Build Path and setup it like into following screenshot.

Eclipse php build path.png

Get last version of sources using a full GIT access

Prerequisite

First you must have a working install of Eclipse. EGit plugin must also have been installed. For this, use the Find And Install process into Eclipse menu, add the GIT update URL:

http://download.eclipse.org/egit/updates

Then choose to install EGit.

You must before create an account on GitHub (https://github.com/) and upload a public RSA or DSA certificate into your account profile.

Then process is same than getting sources with anonymous access.

URL to use for GIT clone is same:

git@github.com:Dolibarr/dolibarr.git

Note that a HTTP URL is also available but it's sometimes offline (so use first one instead):

https://yourgitlogin@github.com/Dolibarr/dolibarr.git

Update your repository

To update your local workspace, right click on Eclipse project and select "Pull".

If you made some changes into your Eclipse workspace on files that were changed into the GIT remote reference, your GIT client will make a merge automatically.

  • If there is conflicts, the merge will mark all conflict files as "conflict" (See later to solve this state).
  • If not, you will get all new version files including all your changes.

If you already have commited some files into your local repository, your workspace will be marked as "Merged". All you have to do is make a commit to validate your local repository as including your changes and changes made by others.

Commit and publish your changes

To see all changes you made into your working directory and waiting to be added into Git:

  • With GIT Command Line Interface:
git status
git diff subdir/filename

To add changes made into your local repository into the GIT index, then commit this index :

  • With Eclipse: Right click on file or directory to commit. Select file to add/remove/update into commit.
  • With GIT Command Line Interface:
git commit -a -m "Commit text"

This will save add and changes into your local branch.

To push them on the GIT repository server,

  • With Eclipse: right click on project and choose "Team - Push to Upstream".
  • With GIT Command Line Interface:
git push

To cancel a commit:

  • With GIT Command Line Interface:
git revert IdCommit  or  git revert HEAD  (for last commit)

Add an external commit into current repository

Some developers may work and do commit into their own Git repository after forking the project. If you are interesting into getting this changes, you can import them with the following steps with Eclipse:

  • First, go into GIT setup view and right click on "Remotes" of your Eclipse Git working space and choose "Create a remote..."
  • Type name or remote fork the developer has create (in most cases, it's developer Git login). For example: "thedevlogin". Choose also "Configure Fetch".
  • Type URI of Git repository of developer. For example: git://github.com/thedevlogin/dolibarr.git. Also add a refspec value to declare the branch you want to get. For example: refs/heads/master:refs/remotes/thedevlogin/master. Click "Save and Fetch". A new entry will be added into "Remote Tracking" making possible to read/get commits done into this branch.

Now, go on command line of your git repository (in most cases on Linux, it's /home/yourlogin/git/yourdolibarr) and type the git cherry-pick command:

git cherry-pick -x commitid

where commitid is value of commit id you want to get.

Once this is done, go back to Eclipse and make a refresh on project. You will see modified files appears with decorators (with conflicts if there is).

Solving a conflict

If a file has been marked as "conflict" after a Pull request, open the file to edit it. Find string "<<<<<<<<<<", you will see part of code that is conflict between "<<<<<<<<<" and ">>>>>>>>". Edit manually code lines and remove "<<<<<<<<" and ">>>>>>>".

Then, right click on file and select "Add".

If you prefer to forget completely all changes you made into all files (so to restore you workspace with content of remote repository), you can make a hard reset:

  • With Eclipse, right click on project top line and select "Reset" then "Hard" then "Reference - HEAD".
  • Using GIT command line tool, you can achieve this with command
git reset --hard HEAD

Tagging sources

To add a tag to a current version:

git tag -m "Tag for x.y.z_YYYYMMDD" "x.y.z_YYYYMMDD"
git push --tags

Creating a new branch

This is command used to start a new branch from a clean develop cloned repository:

git branch x.y
git push origin x.y

Statistics

To count number of changes developers have made between a version x and y:

  • First, run git merge-base to know the id of last common commit between x and y
git merge-base origin/3.1 origin/develop
  • Then run git log to have list of all changes from last common commit to last commit
git log id_found_at_previous_step..HEAD
  • To get total number of added/deleted lines:
git log --ancestry-path --numstat --pretty="%H" id_found_at_previous_step..HEAD | awk 'NF==3 {plus+=$1; minus+=$2} END {printf("+%d, -%d\n", plus, minus)}'


To count number of changes finally between a version x and y (it differs from previous count because in previous count, a change can be done 2 times at two different moment to change differently. With second method, you count change finally found if changes were ok at first try):

  • Use same method than previously but instead of running git log, run git diff.
git diff -b -M --numstat --pretty="%H" id_found_at_previous_step..HEAD | awk 'NF==3 {plus+=$1; minus+=$2} END {printf("+%d, -%d\n", plus, minus)}'


More information in GIT usage is available here.