User:Timothee Flutre/Notebook/Postdoc/2012/08/14
From OpenWetWare
(Difference between revisions)
(→About Git: add git reset) |
(→About Git: add link to example of conflict solving) |
||
| (6 intermediate revisions not shown.) | |||
| Line 15: | Line 15: | ||
* '''Need some help''': the learning curve for git is quite steep at the beginning, so it's always worth browsing [https://help.github.com/ help pages], reading [http://gitref.org/ Git Reference], and searching for questions and answers on [http://stackoverflow.com/ stackoverflow]. | * '''Need some help''': the learning curve for git is quite steep at the beginning, so it's always worth browsing [https://help.github.com/ help pages], reading [http://gitref.org/ Git Reference], and searching for questions and answers on [http://stackoverflow.com/ stackoverflow]. | ||
| + | |||
| + | |||
| + | * '''Conflicts''': when updating one branch with the content of another one (<code>git checkout branch1; git merge branch2</code>), some conflicts can happen, and it is usually hard to know how to solve them properly (but see a concrete example [http://git-scm.com/book/en/Git-Branching-Basic-Branching-and-Merging here]). In the following, branch1 can be master and branch2 can be origin/master, or branch1 can be master and branch2 can be dev. | ||
| + | ** The first solution is to edit each conflicted files by hand, then run <code>git add fileX.txt</code> (staging indicates to git that the conflict is resolved) and finally run <code>git commit -m "merge branch2 and solve conflicts" fileX.txt</code>. | ||
| + | ** The second solution is to ignore the conflicts and overwrite the files of branch1 with the content of branch2, one file at a time: <code>git checkout --patch branch2 fileX.txt</code>. | ||
| + | ** The third solution, even more radical, is to "overwrite" all of branch1 with the content of the branch2, all files at once: <code>git reset --hard branch2</code>. | ||
| + | |||
| + | |||
| + | * '''Tips''': | ||
| + | ** undo uncommitted changes: <code>git checkout myfile.txt</code> | ||
| + | ** usual config: <code>git config --global user.name 'Timothée Flutre'; git config --global user.email 'timflutre@gmail.com'; git config --global i18n.commitEncoding 'utf8'; git config --global i18n.logOutputEncoding 'utf8'</code> | ||
* '''Writing a paper''': in this example, I am writing a paper with two colleagues. We decide to do it as a [http://git-scm.com/book/en/Distributed-Git-Distributed-Workflows centralized workflow], the shared repository being hosted by [https://github.com/ github]. | * '''Writing a paper''': in this example, I am writing a paper with two colleagues. We decide to do it as a [http://git-scm.com/book/en/Distributed-Git-Distributed-Workflows centralized workflow], the shared repository being hosted by [https://github.com/ github]. | ||
| - | ** Each of us needs to [https://github.com/signup/free create a free account]. | + | ** Setting up the infrastructure: |
| - | ** I need to upgrade my account in order to have the right to manage private repositories ([https://github.com/plans/ $7/month]). | + | *** Each of us needs to [https://github.com/signup/free create a free account]. |
| - | ** I create a private repository named "paper" and add my colleagues as collaborators to it. | + | *** I need to upgrade my account in order to have the right to manage private repositories ([https://github.com/plans/ $7/month]). |
| - | ** I retrieve the repository on my local machine: <code>git clone git://github.com/timflutre/paper.git</code> | + | *** I create a private repository named "paper" and add my colleagues as collaborators to it. |
| - | ** I create my first file, for instance "paper_main.tex", and add it to git in my local repository: <code>git add paper_main.tex</code> followed by <code>git commit -m "first commit" paper_main.tex</code>. | + | *** I retrieve the repository on my local machine: <code>git clone git://github.com/timflutre/paper.git</code> |
| - | ** I create one branch per collaborator (the default branch being "master"): <code>git branch tim</code>, then <code>git branch colleague1</code> and finally <code>git branch colleague2</code>. I can list the local branches with <code>git branch</code> and I can switch to my branch with <code>git checkout tim</code> for instance. | + | *** I create my first file, for instance "paper_main.tex", and add it to git in my local repository: <code>git add paper_main.tex</code> followed by <code>git commit -m "first commit" paper_main.tex</code>. |
| - | ** I push the changes I made from my local repo onto github: <code>git push origin master</code>, this for each branch I created. | + | *** I create one branch per collaborator (the default branch being "master"): <code>git branch tim</code>, then <code>git branch colleague1</code> and finally <code>git branch colleague2</code>. I can list the local branches with <code>git branch</code> and I can switch to my branch with <code>git checkout tim</code> for instance. |
| - | ** I send an email to my colleagues telling them that they can retrieve the content of the repository from github into their local machine(s): <code>git clone https://github.com/timflutre/paper.git</code>. | + | *** I push the changes I made from my local repo onto github: <code>git push origin master</code>, this for each branch I created. |
| - | ** Each of us can make modifications on its own branch, and push them on github in order to allow the others to access the changes: <code>git push origin colleague1</code> for instance. | + | *** I send an email to my colleagues telling them that they can retrieve the content of the repository from github into their local machine(s): <code>git clone https://github.com/timflutre/paper.git</code>. |
| - | ** From time to time, one of us has the responsibility to merge the changes and update the "master" branch with the latest version. | + | ** Typical working cycle: |
| - | ** Once this is done, the others need to retrieve the new content of "master" in their local repo: <code>git checkout master</code>, <code>git fetch origin</code>, <code>git diff master origin/master</code>, <code>git merge origin/master</code>. | + | *** Each of us can make modifications on its own branch, and push them on github in order to allow the others to access the changes: <code>git push origin colleague1</code> for instance. |
| - | ** Then, they need to update their local branch with the new content of "master": <code>git checkout colleague1</code>, <code>git diff --name-status colleague1..master</code>. This will list the files having differences between their local branch and the new content of "master". | + | *** From time to time, one of us has the responsibility to merge the changes and update the "master" branch with the latest version. |
| - | ** One can look at the differences file by file: <code>git diff --color-words colleague1:paper_main.tex master:paper_main.tex</code>. The options "--color-words" is especially useful in LaTeX. | + | *** Once this is done, the others need to retrieve the new content of "master" in their local repo: <code>git checkout master</code>, <code>git fetch origin</code>, <code>git diff master origin/master</code>, <code>git merge origin/master</code>. |
| - | ** To merge the content of "master" into his own branch, we do: <code>git merge master</code>. | + | *** Then, they need to update their local branch with the new content of "master": <code>git checkout colleague1</code>, <code>git diff --name-status colleague1..master</code>. This will list the files having differences between their local branch and the new content of "master". |
| - | ** | + | *** One can look at the differences file by file: <code>git diff --color-words colleague1:paper_main.tex master:paper_main.tex</code>. The options "--color-words" is especially useful in LaTeX. |
| + | *** To merge the content of the recently-updated local "master" into his own local branch, we do: <code>git merge master</code>. | ||
| + | ** Tips: don't version the output pdf in the repository because, as it is binary, git can't merge it properly. But you can add a Makefile (see below) and, by entering <code>make main -i</code> on the command-line, it will compile your pdf document when you need it | ||
| + | |||
| + | <nowiki> | ||
| + | all: main supp | ||
| + | |||
| + | main: | ||
| + | latex paper_main.tex | ||
| + | bibtex paper_main | ||
| + | latex paper_main.tex | ||
| + | latex paper_main.tex | ||
| + | pdflatex paper_main | ||
| + | |||
| + | supp: | ||
| + | latex paper_supplements.tex | ||
| + | bibtex paper_supplements | ||
| + | latex paper_supplements.tex | ||
| + | latex paper_supplements.tex | ||
| + | pdflatex paper_supplements | ||
| + | |||
| + | clean: | ||
| + | rm -f *~ *.aux *.dvi *.log *.pdf *.bbl *.blg *.toc | ||
| + | </nowiki> | ||
<!-- ##### DO NOT edit below this line unless you know what you are doing. ##### --> | <!-- ##### DO NOT edit below this line unless you know what you are doing. ##### --> | ||
Revision as of 19:33, 9 January 2013
Main project page Previous entry Next entry
| |
About Git
all: main supp main: latex paper_main.tex bibtex paper_main latex paper_main.tex latex paper_main.tex pdflatex paper_main supp: latex paper_supplements.tex bibtex paper_supplements latex paper_supplements.tex latex paper_supplements.tex pdflatex paper_supplements clean: rm -f *~ *.aux *.dvi *.log *.pdf *.bbl *.blg *.toc | |



