本文取自 https://stackoverflow.com/questions/6188780/git-latex-workflow

感谢 abcd@stackoverflow

Changes to your LaTeX workflow:

The first step in efficiently managing a git+latex workflow is to make a few changes to your LaTeX habits.

  • For starters, write each sentence on a separate line. Git was written to version control source code, where each line is distinct and has a specific purpose. When you write documents in LaTeX, you often think in terms of paragraphs and write it as a free flowing document. However, in git, changes to a single word in a paragraph get recorded as a change to the entire paragraph.

    One solution is to use git diff --color-words (see my answer to a similar question where I show an example). However, I must emphasize that splitting into separate lines is a much better option (I only mentioned it in passing in that answer), as I've found it to result in very minimal merge conflicts.

  • If you need to look at the code diff, use git's native diff. To see the difference between two arbitrary commits (versions), you can do so with the shas of each of the commits. See the documentation for more details and also this question

    On the other hand, if you need to look at the diff of your formatted output, use latexdiff which is an excellent utility (written in perl) that takes two latex files and produces a neat diffed output in pdf like this (image source):

    You can combine git and latexdiff (plus latexpand if needed) in a single command using git-latexdiff (e.g. git latexdiff HEAD^ to view the diff between your worktree and the last-but-one commit).

  • If you're writing a long document in latex, I'd suggest splitting different chapters into their own files and call them in the main file using the \include{file} command. This way it is easier for you to edit a localized part of your work, and it is also easier for version control, as you know what changes have been made to each chapter, instead of having to figure it out from the logs of one big file.

Using git efficiently:

  • Use branches!. There is perhaps no better advice I can give. I've found branches to be very helpful to keep track of "different ideas" for the text or for "different states" of the work. The master branch should be your main body of work, in its most current "ready to publish" state i.e., if of all the branches, if there is one that you are willing to put your name on it, it should be the master branch.

    Branches are also extremely helpful if you are a graduate student. As any grad student will attest, the advisor is bound to have numerous corrections, most of which you don't agree with. Yet, you might be expected to atleast change them for the time being, even if they are reverted later after discussions. So in such cases, you could create a new branch advisor and make changes to their liking, at the same time maintaining your own development branch. You can then merge the two and cherry pick what you need.

  • I would also suggest splitting each section into a different branch and focus only the section corresponding to the branch that you're on. Spawn a branch when you create a new section or dummy sections when you make your initial commit (your choice, really). Resist the urge to edit a different section (say, 3) when you're not on its branch. If you need to edit, commit this one and then checkout the other before branching. I find this very helpful because it keeps the history of the section in its own branch and also tells you at a glance (from the tree) how old some section is. Perhaps you've added material to section 3 that requires tweaking to section 5... Of course, these will, in all probability, be observed during a careful reading, but I find it helpful to see this at a glance so that I can shift gears if I'm getting bored of a section.

    Here's an example of my branches and merges from a recent paper (I use SourceTree on OS X and git from the command line on Linux). You'll probably notice that I'm not the world's most frequent committer nor do I leave useful comments all the time, but that's no reason for you not to follow those good habits. The main takeaway message is that working in branches is helpful. My thoughts, ideas and development proceeds non-linearly, but I can keep track of them via branches and merge them when I'm satisfied (I also had other branches that led nowhere that were later deleted). I can also "tag" commits if they mean something (e.g., initial submissions to journals/revised submissions/etc.). Here, I've tagged it "version 1", which is where the draft is as of now. The tree represents a week's worth of work.

  • Another useful thing to do would be to make document wide changes (such as changing \alpha to \beta everywhere) commits on their own. That way, you can revert changes without having to rollback something else along with it (there are ways you can do this using git, but hey, if your can avoid it, then why not?). The same goes for additions to the preamble.

  • Use a remote repo and push your changes upstream regularly. With free service providers like github and bitbucket (the latter even allows you to create private repos with a free account), there is no reason to not be using these if you're working with git/mercurial. At the very least, consider it as a secondary backup (I hope you have a primary one!) for your latex files and a service that allows you to continue editing from where you left on a different machine.

[转] Git + LaTeX workflow的更多相关文章

  1. Using git-flow to automate your git branching workflow

    Using git-flow to automate your git branching workflow Vincent Driessen’s branching model is a git b ...

  2. Git/Bitbucket Workflow

    中文 http://blog.jobbole.com/76843/ 英文 https://www.atlassian.com/git/tutorials/comparing-workflows#cen ...

  3. [Git] An efficient GIT workflow for mid/long term projects

    reference : http://fle.github.io/an-efficient-git-workflow-for-midlong-term-projects.html Our full-w ...

  4. GIT TEAMWORK

    Learn GIT TEAMWORK generalizations Congratulations, you now know enough to start collaborating on Gi ...

  5. GIT BRANCHING

    GIT BRANCHING generalizations Let's take a moment to review the main concepts and commands from the ...

  6. hg和git命令对照表

    hg和git命令对照表 来源 https://github.com/sympy/sympy/wiki/Git-hg-rosetta-stone Git hg rosetta stone   muxat ...

  7. LaTeX简历模板

    %# -*- coding:utf-8 -*- %% start of file `template_en.tex'. %% Copyright 2006-1008 Xavier Danaux (xd ...

  8. GIT团队合作探讨之二--Pull Request

    pull request是github/bitbucket给开发人员实现便利合作提供的一个feature.他们提供一个用户友好的web界面在进代码之前来讨论这些变更. 简单说,pull request ...

  9. Fighting regressions with git bisect---within git bisect algorithm

    https://www.kernel.org/pub/software/scm/git/docs/git-bisect-lk2009.html Fighting regressions with gi ...

随机推荐

  1. Web前端框架与移动应用开发第七章:二

    3.练习3:抽奖大转盘 注意事项:需要使用Zepto.js,区别于zepto.min.js 实现效果:转盘转动抽奖 html <!DOCTYPE html><html>< ...

  2. POJ - 2057 The Lost House(树形DP+贪心)

    https://vjudge.net/problem/POJ-2057 题意 有一只蜗牛爬上某个树枝末睡着之后从树上掉下来,发现后面的"房子"却丢在了树上面,.现在这只蜗牛要求寻找 ...

  3. sweetalert插件的使用

    sweetalert是一个漂亮的弹窗插件,使用它可以完成各种炫酷的弹窗效果 链接:sweetalert 实例 删除演示 urls.py from django.contrib import admin ...

  4. VM克隆后找不到eth0的问题解决

    问题描述 使用VM WorkStation新建虚拟机A,查看IP信息,显示结果: [root@centos65x64 ~]# ifconfig -a eth0 Link encap:Ethernet ...

  5. C#窗口编程时TextBox中的换行

    注意Windows下的换行符是\r\n.只使用\n是无法完成换行的

  6. [译]Walkthrough: Using MSBuild

    原文 MSBuild是微软VS的Build平台. 你可以在Visual Studio或Windows命令行中运行MSBuild.在这我们使用VS创建一个MSBuild项目.你可以在VS中编辑项目文件, ...

  7. springboot12-zuul

    Zuul 相当于是设备和 Netflix 流应用的 Web 网站后端所有请求的前门,提供动态路由,监控,弹性,安全等的边缘服务 所有请求都经过网关(API Gateway)zuul,然后转发到各个子服 ...

  8. windows Apache 环境下配置支持HTTPS的SSL证书

    windows Apache 环境下配置支持HTTPS的SSL证书 1.准备工作 1)在设置Apache + SSL之前, 需要做: 安装Apache, 下载安装Apache时请下载带有SSL版本的A ...

  9. python之字典的增删改查

    Python字典是另一种可变容器模型,且可存储任意类型对象,如字符串.数字.元组等其他容器模型.字典都是无序的,但查询速度快. 字典是一个key/value的集合,key可以是任意可被哈希(内部key ...

  10. Linux环境及基础命令(一)

    Linux环境及基础命令 一.认识Linux系统 略 二.配置Linux系统远程登录 2.1虚拟机系统配置 2.11虚拟机配置 统一NAT模式 虚拟机连不上 确定VMnet8网卡的IP地址(每台虚拟机 ...