Difference between revisions of "GIT client (EP)"

(Created page with "Category:Linux Category:Development This page explains how to work with GIT. It is based on our current way of working for ''European Parliament - DG Trad - Cat4trad...")
 
 
Line 154: Line 154:
 
git format-patch HEAD~5
 
git format-patch HEAD~5
 
</syntaxhighlight>
 
</syntaxhighlight>
** Copy the generated <code>.patch</code> file to the other folder you'd like to apply it
+
 
 +
* Copy the generated <code>.patch</code> file to the other folder you'd like to apply it
  
  
Line 170: Line 171:
  
 
=In ECLIPSE=
 
=In ECLIPSE=
 +
 +
 
To add a GIT repository in Eclipse IDE:
 
To add a GIT repository in Eclipse IDE:
 
* add an existing repository
 
* add an existing repository
Line 178: Line 181:
  
 
=Documentation=
 
=Documentation=
 +
 
* Short introduction: [http://rogerdudler.github.io/git-guide/ Git short guide]
 
* Short introduction: [http://rogerdudler.github.io/git-guide/ Git short guide]
 
* Git complete guide (with videos): [https://docs.microsoft.com/en-us/azure/devops/repos/git/pulling?view=vsts&tabs=visual-studio Visual Studio GIT howTo]
 
* Git complete guide (with videos): [https://docs.microsoft.com/en-us/azure/devops/repos/git/pulling?view=vsts&tabs=visual-studio Visual Studio GIT howTo]
 
* Complete and excellent introduction, all in 1 blog post: [https://itnext.io/become-a-git-pro-in-just-one-blog-a-thorough-guide-to-git-architecture-and-command-line-interface-93fbe9bdb395 Become a Git pro in just one blog: a thorough guide to git architecture and command line interface]
 
* Complete and excellent introduction, all in 1 blog post: [https://itnext.io/become-a-git-pro-in-just-one-blog-a-thorough-guide-to-git-architecture-and-command-line-interface-93fbe9bdb395 Become a Git pro in just one blog: a thorough guide to git architecture and command line interface]

Latest revision as of 07:51, 19 November 2018


This page explains how to work with GIT. It is based on our current way of working for European Parliament - DG Trad - Cat4trad.


Last update: 2018-11-19


Get source code

  • Clone repository
git clone http://gdiaz@scm.ep-foundry.ep.parl.union.eu/git/scm/tradcat4trad/trad-das-cat4trad.git
cd trad-das-cat4trad


(i) by default you work on the 'master' branch


Switch to REMOTE branch

  • View current branch
git branch


  • View available branches
git branch -r


  • Switch to REMOTE branch (ex: c4t-v3.5.1)
git checkout -b c4t-v3.5.1 origin/c4t-v3.5.1


  • Check that you work with the branch
git branch


  • Update to latest version
git pull


Get remote changes

Git has a 2 step process for gettings changes from others:

  1. fetch
  2. merge


Careful: make sure that you don't have any staged or unstaged changes. GIT won't let you merge changes if you have anything staged for the next commit. You must commit everything first before pull.


Fetch changes

FETCH does not merge any changes into your local branches, it only downloads the new commits for your review.

To download changes into the local repository but without applying them:

git fetch


Merge changes into local repository

Apply changes downloaded through fetch using the MERGE command. MERGE takes the commits retrieved from fetch and tries to add them to your local branch. The merge will keep the commit history of your local changes so that when you share your branch with push Git will know how others should merge your changes.

The challenge with merge is when a commit taken from fetch conflicts with an existing unpushed commit on your branch. Git is generally very smart about resolving merge conflicts automatically, but sometimes you must resolve merge conflicts manually and complete the merge with a new merge commit.


To apply fetched changes to the local repository and branches:

git merge

# You can merge without committing using --no-commit to attempt to perform the merge but not commit the final changes
# which gives you a chance to inspect the changed files before finalizing the merge with a commit.
git merge --no-commit


Fetch and merge

PULL does a fetch and then a merge to download the commits and update your local branch in one command instead of two. Use PULL to quickly bring your branch up to date with the remote when you aren't worried about reviewing the changes before merging them into your own branch.


branch update

To apply PULL on the current branch

git pull


GIT stash

When you want to keep your changes - but not commit them - you can use STASH.

Example:

  • You have change a setting file, but you do not want to commit
  • In current state this change is preventing you to pull (because of a merge issue)
  • Apply stash to save your change, pull the latest version of the branch, stash apply to reput your changes again


Stashing means secretly hiding something and when we stash changes, they are stored in safe place. This is where git reset --hard contradicts. Git hard reset will get rid of changes in tracked files while stash will do the same but it can save the changes in secret location. These change can be re-applied if needed.


// TO BE CONTINUED


integrate other changes

To directly merge the work from remote branch into your local branch, PULL a remote branch into a local one by passing remote branch information into pull:

# let's assume you're working on c4t-v3.5.1
git pull origin/master .



GIT patch

Creation of patch

  • Create GIT patch
    • Commit and push your changes on the branch
    • Extract the changes into a patch file
# to extract last changes (single commit)
git format-patch HEAD~1
# to extract last 5 commits changes
git format-patch HEAD~5
  • Copy the generated .patch file to the other folder you'd like to apply it


  • Apply patch
    • Go to the folder were you want to apply the patch
    • Ensure the folder is up to date (to avoid conflicts afterwards)
git pull
# Apply patch
git am



In ECLIPSE

To add a GIT repository in Eclipse IDE:

  • add an existing repository
  • Import maven project from FILE SYSTEM (not from GIT view!)



Documentation