7 Initializing a working copy
8 ---------------------------
10 Use the easy-setup shell script::
12 curl -O https://raw.githubusercontent.com/odoo/odoo/master/odoo.py | python2
14 it will will ask a few questions and create a local copy.
22 Remotes are "remote repositories" which can be fetched from and pushed
23 to. Remotes can be listed with ``git remote``\ [#remote-default]_ and a local
24 repository can have any number of remotes. The setup script creates 2 remotes:
27 the official repository and main branches, roughly corresponds to the old
28 "mainline" branches in bazaar. You should never need to push to it, and by
29 default your local copy is configured to forbid it.
31 a grab-bag of development branches, you can push your work to it so other
32 coworkers can work with you.
37 The working copy and each remote contain multiple branches. Local branches can
38 be listed by ``git branch``, remote branches can be listed with ``git branch
39 -r``. Both types can be listed with ``git branch -a``.
41 Work is only possible on local branches, even though it's possible to check
42 out a remote branch work on it will be lost.
47 ``bzr commit`` takes all alterations to the working copy and creates a commit
48 from them. Git has an intermediate step called "staging". ``git commit`` will
49 create a commit from what has been staged, not from the working copy\
50 [#commit-no-staging]_. Staging is done with ``git add``. A commit with nothing
51 staged is a null operation.
55 It's possible for a single file to have changes in both the index and
56 working copy: if a file is altered, staged and altered again, the second
57 set of change has to be staged separately
62 Git has no sequential identifier, each commit is uniquely identified by a SHA
63 (40 hexadecimal characters) roughly corresponding to a bazaar
64 revision-id. Providing the full sha is rarely necessary, any unique leading
65 substring is sufficient, e.g. ``dae86e`` will probably stand in for
66 ``dae86e1950b1277e545cee180551750029cfe735``.
68 Basic development workflow
69 --------------------------
71 * update your remotes with ``git fetch --all``
72 * create your development branch with ``git checkout -b <branch_name>
73 <source_branch>``. For instance if you wanted to add support for full-text
74 search in master you could use ``git checkout -b master-fts-xxx odoo/master``
75 * do your changes, stage them with ``git add`` and commit them with ``git
77 * if your branch is long-lived, you may want to update it to its parent
79 - update the remotes with ``git fetch --all``
80 - merge the remote branch into the local one with ``git merge --no-ff
83 * to push the branch to the development repository, use ``git push -u dev
84 <branchname>``, this will automatically create a branch called
85 ``<branchname>`` on dev. Next time around you do not have to use ``-u``
86 * once the feature is done, create a pull request
88 .. should we promote rebase? That would lead to cleaner histories, but if the
89 branch is already pushed it requires force-pushing since the branch can't
92 .. git automatically creates a merge commit, should we configure merge with
95 .. make --no-ff the default in the config script?
97 .. warn about ``git pull``? It is ~ ``git fetch; git merge`` and should
102 .. format for specifying issues? e.g. closes #42?
107 Converting your feature branches from bazaar
108 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
110 `The readme`_ has some instructions.
112 Viewing history: ``git log``
113 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
115 ``git log`` fulfills the same role as ``bzr log`` and is fairly similar, with
118 * ``git log`` has no ``-r`` argument, its first argument (optional) is a
120 * ``git log`` always operates on ranges, if a single commit is provided (via
121 hash, tag, branch or other) it will list the specified commit *and all of
122 its ancestors*. To see a single commit, use ``git show``.
123 * ``git log``'s second positional argument is a path (file or
124 directory). Because both are optional, if both a revision and a file match
125 the revision will be selected. It is recommended to use ``--`` before a file
130 * ``git log`` will actually work if given a directory, instead of pegging the
132 * ``git log`` works with removed files or directories without having to
133 provide a revision during which the file or directory still existed
134 * ``git log`` has *lots* of options to customize the output, e.g. ``-p`` will
135 display the changes to each file\ [#log-patch-empty]_, ``--name-status``
136 will list the changed files and how they changed SVN-style (with a ``M`` or
137 ``D`` prefix), ``--name-only`` will just list the changed files, ``--stat``
138 generates a diffstat view, ``--grep`` filters by grepping on the commit
141 Reverting uncommitted changes
142 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
144 .. danger:: Do *not* use ``git revert``, it does something completely
145 different than ``bzr revert``
147 * If you have altered files which you want to revert, use ``git checkout --
148 <path>``. To revert every file in the directory, use ``git checkout -- .``
149 * If you have staged a file and you want to unstage it, use ``git reset HEAD
150 <file>``. This will not revert the file's changes, the file will be marked
153 Diffing: ``git diff``
154 ~~~~~~~~~~~~~~~~~~~~~
156 ``git diff`` is fairly similar to ``bzr diff``: it compares the working copy
157 with stored content and can be restricted to a given file path. However:
159 * ``git diff`` compares the working copy and the staging area, not the latest
161 * ``git diff --staged`` compares the staging area and the latest commit
162 * ``git diff HEAD`` ignores the staging area and compares the working copy
163 with the latest commit. More generally ``git diff <commit>`` will diff the
164 working copy and the specified commit
165 * to diff between commits, simply pass the commit identifiers (no ``-r``
167 * ``git diff --stat`` provides a diffstat-view of the diff, and can be
168 combined with other flags. It can be used as an intermediate between ``git
169 status`` and ``git status -s``
171 Update to a previous revision
172 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
174 ``git checkout`` takes an arbitrary commit, the equivalent to ``bzr update
175 -r<rev>`` is thus ``git checkout <rev>``.
180 ``bzr cat -r<revision> <filename>`` shows the file ``<filename>`` as it was at
181 ``<revision>``. The Git equivalent is ``git show <revision>:<filename>``
183 Incorrect last commit: fix it
184 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
186 If the last commit has to be fixed a bit (error, missing data,
187 incomplete/incorrect commit message) it can be fixed with ``git commit
188 --amend``. Instead of creating a new commit, it adds whatever is being
189 committed to the previous commit.
191 Incorrect last commit: remove it
192 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
194 If the last commit has to be removed entirely (similar to ``bzr uncommit``),
195 use ``git reset HEAD~1``.
197 .. danger:: do not use this command or the previous one on commits you have
206 ``checkout``, ``add``, ``commit``, ``reset`` and ``stash`` can take a ``-p``
207 flag, which allows operating (staging, reverting, ...) on a subset of the
208 file. It opens a UI allowing the selection (or not) of each patch hunk, and
209 even the splitting of hunk if they're too big.
211 Allows reverting only part of the changes to a file, or cleanly splitting
212 refactorings and fixes mixed in a file.
217 The default ``status`` command is very verbose (though useful, it provides
218 instructions for reverting things). The ``-s`` flag provides an SVN-like
219 display instead with just a listing of files and :abbr:`A (Added)`, :abbr:`M
220 (Modified)` or :abbr:`D (Deleted)` flags next to them. Each file can have 2
221 flags, the first is for the index (difference between the last commit and the
222 index) and the and the second is for the working copy (difference between the
223 index and the working copy).
225 ``checkout`` shortcut
226 ~~~~~~~~~~~~~~~~~~~~~
228 ``checkout -`` will behave like ``cd -``, it will switch to the previously
229 checked-out branch/commit
231 .. [#remote-default] by default, ``git remote`` will only give the names of
232 the various remotes. ``git remote -v`` will give the name
233 and URL of each remote.
235 .. [#commit-no-staging] the ``-a`` option will automatically stage modified
238 .. [#log-patch-empty] but only the changes performed by this actual commit,
239 for a merge the merged changes are not considered part
242 .. _the readme: https://github.com/odoo/odoo/blob/master/README.md#migration-from-bazaar