[MacPorts] WorkingWithGit modified

MacPorts noreply at macports.org
Fri Aug 26 11:49:40 PDT 2016


Page "WorkingWithGit" was changed by cal at macports.org
Diff URL: <https://trac.macports.org/wiki/WorkingWithGit?action=diff&version=50>
Revision 50
Comment: Reorganize and consolidate common sections
Changes:
-------8<------8<------8<------8<------8<------8<------8<------8<--------
Index: WorkingWithGit
=========================================================================
--- WorkingWithGit (version: 49)
+++ WorkingWithGit (version: 50)
@@ -5,12 +5,6 @@
 [[PageOutline]]
 
 == Initial setup == #Initialsetup
-
-{{{
-#!comment
-TODO: Move this section to a separate wiki page.
-}}}
-
 Git commits contain your name and email address. You should set them in your git configuration using the following commands:
 {{{
 git config --global user.name "Your Name"
@@ -18,57 +12,16 @@
 }}}
 If you work on multiple Git projects and do not want to modify your email address for those, these commands can also be run without `--global` in a clone of MacPorts' repositories to only change the option for these repositories. If you are not a MacPorts committer, use any email address.
 
-'''T.B.D.:''' MacPorts ports contributors should be encouraged to fork the original MacPorts {{{git}}} repository and introduce changes only in their forked repos. Contributions can then be "filed" to the original repo using GitHub's pull requests (PR). These PRs allow for user-friendly reviewing, commenting and in the future possibly also immediate issuing of CI builds.
-
-
-== Common `git` tasks while working with ports ==
-
-Then
-{{{
-svn checkout https://svn.macports.org/repository/macports/trunk/dports
-}}}
-becomes 
-{{{
-git clone git at github.com:macports/ports.git
-}}}
-When you clone you will get the entire history of the ports tree, with the latest version being checked out in the filesystem.
-After you make a change, you can run {{{ git status }}}
-and get something like this.
-{{{
-On branch master
-Your branch is up-to-date with 'origin/master'.
-Changes not staged for commit:
-  (use "git add <file>..." to update what will be committed)
-  (use "git checkout -- <file>..." to discard changes in working directory)
-
-	modified:   aqua/iTerm2/Portfile
-
-no changes added to commit (use "git add" and/or "git commit -a")
-}}}
-What this tells me, is that I've changed a Portfile, but not done anything.
-After that, you can add the files that you want to add to your commit using {{{git add aqua/iTerm2/Portfile}}}.
-Now, {{{git status}}} will look like:
-{{{
-On branch master
-Your branch is up-to-date with 'origin/master'.
-Changes to be committed:
-  (use "git reset HEAD <file>..." to unstage)
-
-	modified:   aqua/iTerm2/Portfile
-}}}
-Then run {{{git commit}}} and everything is set. On your machine. To push to github you then have to run {{{git push}}}.
-
-
-== Common `git` tasks while working with MacPorts base ==
-
-=== Checking out a working copy === #clone
-The source code of MacPorts itself is no longer managed in the same repository as all ports. Contrary to Subversion, checking out a sub-directory of a repository is not possible with Git. In order to avoid that all port maintainers have to clone the complete history of MacPorts base as well, the Subversion repository has been split into multiple separate repositories. MacPorts base is now available using
-{{{
-git clone git at github.com:macports/base.git # or
-git clone https://github.com/macports/base.git # if SSH does not work on your network
-}}}
-
-See the [#reposplit section on repository splitting during the export] to get an overview of where a path in the old Subversion history is now available in Git.
+
+
+
+
+== Common `git` tasks & notes about MacPorts' Subversion export ==
+
+
+=== Getting a working copy ===
+To start working with git, you need a copy of the sources. Follow the sections for [#cloneports getting the ports tree] or [#clone MacPorts base], depending on where you want to make changes, then continue with the next section.
+
 
 === Committing changes in your working copy === #commit
 A fundamental difference between Subversion and Git working copies is that `svn commit` by default commits all changes in your working copy, but `git commit` by default commits none. Git uses a staging area called "index" that allows you to mark changes for inclusion in the next commit. To add changes to the next commit, use
@@ -101,82 +54,6 @@
 
 Note that the push will fail if the remote repository has new changes. Contrary to Subversion, it does not matter whether your changes conflict with the remote ones. If this happens, you must update your local working copy as described in the [#updating section on fetch the latest changes] and re-try the push.
 
-=== Merge a single change from master into a release branch === #cherrypick
-The equivalent to Subversion's `svn merge -c <revision> .` is `git cherry-pick`. Use `git cherry-pick` to apply a single change from master to a release branch. To do this, look up the commit ID of the commit you want to pick:
-{{{
-git log
-# copy the commit ID
-}}}
-Switch to the target branch of the cherry pick:
-{{{
-git checkout release_2_3
-}}}
-Cherry-pick the commit. It is good practice to pass `-x` to `git cherry-pick`, which will automatically add a "Cherry picked from commit <commmitID>" line to the commit message of your cherry pick. You will have the option to modify the commit message, e.g. to describe why the backport was necessary.
-{{{
-git cherry-pick -x <commitID>
-}}}
-Finally, push the new commit using
-{{{
-git push origin <branchname>
-}}}
-
-== Common `git` tasks & notes about MacPorts' Subversion export ==
-=== Fetching the latest changes === #updating
-Git's equivalent to `svn update` is a little more complicated due to Git's distributed nature. Most of the complexity is not visible if you do not have commits in your working copy that have not been pushed yet. If both the local and the remote repository have changes (git calls them "diverged"), you will run into one of Git's core principles: Every commit has (at least) one parent commit, i.e. the commit history forms a directed acyclic graph.
-
-==== Background knowledge ====
-
-A picture is worth a thousand words:
-{{{
- A --- B --- C ---- R1 ---- R2 ---- R3  <= origin/master
-              \
-               +--- L1 ---- L2          <= master
-}}}
-A, B and C are commits that are both in your local and in the remote repository. R1-3 are commits that have been pushed into the remote repository "origin"'s master branch while you were working. L1 and L2 are commits you prepared locally on your master branch. Git offers two different ways to bring R1-3 into your local branch:
-
-===== Merging =====
-A merge commit, created by `git merge`, is a commit that has multiple parents. If no conflict occurs, merge commits do not usually have a diff attached (i.e. they do not modify files). On conflict, merge commits contain the diff that resolves the conflict. In pictures:
-{{{
- A --- B --- C ---- R1 ---- R2 ---- R3   <= origin/master
-              \                      \
-               +--- L1 ---- L2 ------ M  <= master
-}}}
-The new commit M is the merge commit and can be pushed back to origin. This preserves the information that work was done in parallel, but unfortunately tends to mess up the history graph. See the [raw-attachment:commit-history-with-excessive-merging.png attached screenshot] of a commit history that always merges. To avoid this, you can instead rebase your changes.
-
-===== Rebasing =====
-Rebasing commits rewrites their parent commit IDs and avoids the need for a merge commit. Running `git rebase origin/master` will take all commits in your local working copy that are not yet pushed and attach them after the end of `origin/master`, which yields this picture:
-{{{
- A --- B --- C ---- R1 ---- R2 ---- R3   <= origin/master
-                                      \
-                                       L1' ---- L2'  <= master
-
-}}}
-Note that L1 and L2 have been modified by this operation; their commit IDs changed because of that. This new state can be pushed back to origin without the need for a merge commit, and the history graph will stay linear. '''We recommend that all developers rebase their changes rather than merge when conflicts occur during pushing.'''
-
-==== Putting the background knowledge into production ====
-First, get all new commits from the remote repository using `git fetch <remote-name>`, where `<remote-name>` identifies the repository from which you want to fetch and defaults to "origin":
-{{{
-git fetch
-}}}
-Then, rebase your local changes (if any) on top of any new changes in the remote repository and fix any conflicts that occur:
-{{{
-git rebase origin/master
-}}}
-
-Because these two operations are very common, Git offers a shorthand for them:
-{{{
-git pull --rebase
-}}}
-
-'''Note:''' `git rebase` requires that you do not have uncommitted modifications in your working copy. If you have modifications, you can temporarily save them using `git stash` and restore them after the rebase using `git stash pop`.
-
-'''Warning:''' `git pull` without the `--rebase` flag is a shorthand for `git fetch && git merge origin/master`, which will automatically create a merge commit if it thinks that's necessary.
-
-If you do not want to remember passing `--rebase` to `git pull` every time you run it, you can set a couple of [https://git-scm.com/docs/git-config git-config(1)] options to make it the default:
-
- - Setting `pull.rebase` to `true` will change the default to always rebase when calling `git pull`. Note that this will also flatten any local merge commits you might have committed on purpose with `git merge`, which might be undesirable when merging development branches for MacPorts base. Consider using the `preserve` setting, which avoids this.
- - Rebasing can be enabled on a per-branch basis using the `branch.<name>.rebase` setting, which accepts the same values as `pull.rebase`.
- - You can make `branch.<name>.rebase true` the default for all branches that you clone by setting `branch.autoSetupRebase` to `always`. This allows you to change the setting back to a different value for specific branches but still keep the default to rebase. Note that this setting will not affect branches that you have already created.
 
 === Commit messages === #commitmessages
 There are a number of conventions to writing Git commit messages. For a detailed explanation, see http://chris.beams.io/posts/git-commit/. As a tl;dr, here are seven short rules:
@@ -191,6 +68,65 @@
 
 If you don't want to remember these rules, you can configure your git client to load a template whenever it prompts you for a commit message by setting the `commit.template` [https://git-scm.com/docs/git-config git-config(1)] option. The KDE developers [https://quickgit.kde.org/?p=macports-kde.git&a=blob&h=14f952f776b9f54263671cc2aba5886c6ebee75b&f=contrib%2Fgit-setup%2F.git-commit-template&o=plain have a nice example].
 
+
+=== Fetching the latest changes === #updating
+Git's equivalent to `svn update` is a little more complicated due to Git's distributed nature. Most of the complexity is not visible if you do not have commits in your working copy that have not been pushed yet. If both the local and the remote repository have changes (git calls them "diverged"), you will run into one of Git's core principles: Every commit has (at least) one parent commit, i.e. the commit history forms a directed acyclic graph.
+
+==== Background knowledge ====
+
+A picture is worth a thousand words:
+{{{
+ A --- B --- C ---- R1 ---- R2 ---- R3  <= origin/master
+              \
+               +--- L1 ---- L2          <= master
+}}}
+A, B and C are commits that are both in your local and in the remote repository. R1-3 are commits that have been pushed into the remote repository "origin"'s master branch while you were working. L1 and L2 are commits you prepared locally on your master branch. Git offers two different ways to bring R1-3 into your local branch:
+
+===== Merging =====
+A merge commit, created by `git merge`, is a commit that has multiple parents. If no conflict occurs, merge commits do not usually have a diff attached (i.e. they do not modify files). On conflict, merge commits contain the diff that resolves the conflict. In pictures:
+{{{
+ A --- B --- C ---- R1 ---- R2 ---- R3   <= origin/master
+              \                      \
+               +--- L1 ---- L2 ------ M  <= master
+}}}
+The new commit M is the merge commit and can be pushed back to origin. This preserves the information that work was done in parallel, but unfortunately tends to mess up the history graph. See the [raw-attachment:commit-history-with-excessive-merging.png attached screenshot] of a commit history that always merges. To avoid this, you can instead rebase your changes.
+
+===== Rebasing =====
+Rebasing commits rewrites their parent commit IDs and avoids the need for a merge commit. Running `git rebase origin/master` will take all commits in your local working copy that are not yet pushed and attach them after the end of `origin/master`, which yields this picture:
+{{{
+ A --- B --- C ---- R1 ---- R2 ---- R3   <= origin/master
+                                      \
+                                       L1' ---- L2'  <= master
+
+}}}
+Note that L1 and L2 have been modified by this operation; their commit IDs changed because of that. This new state can be pushed back to origin without the need for a merge commit, and the history graph will stay linear. '''We recommend that all developers rebase their changes rather than merge when conflicts occur during pushing.'''
+
+==== Putting the background knowledge into production ====
+First, get all new commits from the remote repository using `git fetch <remote-name>`, where `<remote-name>` identifies the repository from which you want to fetch and defaults to "origin":
+{{{
+git fetch
+}}}
+Then, rebase your local changes (if any) on top of any new changes in the remote repository and fix any conflicts that occur:
+{{{
+git rebase origin/master
+}}}
+
+Because these two operations are very common, Git offers a shorthand for them:
+{{{
+git pull --rebase
+}}}
+
+'''Note:''' `git rebase` requires that you do not have uncommitted modifications in your working copy. If you have modifications, you can temporarily save them using `git stash` and restore them after the rebase using `git stash pop`.
+
+'''Warning:''' `git pull` without the `--rebase` flag is a shorthand for `git fetch && git merge origin/master`, which will automatically create a merge commit if it thinks that's necessary.
+
+If you do not want to remember passing `--rebase` to `git pull` every time you run it, you can set a couple of [https://git-scm.com/docs/git-config git-config(1)] options to make it the default:
+
+ - Setting `pull.rebase` to `true` will change the default to always rebase when calling `git pull`. Note that this will also flatten any local merge commits you might have committed on purpose with `git merge`, which might be undesirable when merging development branches for MacPorts base. Consider using the `preserve` setting, which avoids this.
+ - Rebasing can be enabled on a per-branch basis using the `branch.<name>.rebase` setting, which accepts the same values as `pull.rebase`.
+ - You can make `branch.<name>.rebase true` the default for all branches that you clone by setting `branch.autoSetupRebase` to `always`. This allows you to change the setting back to a different value for specific branches but still keep the default to rebase. Note that this setting will not affect branches that you have already created.
+
+
 === Reverting changes === #revert
 Subversion has two methods for reverting changes: `svn revert`, which drops uncommitted local modifications and restores the committed state and `svn merge -c -12345` to undo committed changes.
 
@@ -199,6 +135,7 @@
  - To drop uncommitted modifications, use `git checkout -- <filename>`. If you had already added the file to the index using `git add`, you have to unstage it first using `git reset HEAD <filename>`. `git status` prints these commands, so you don't have to remember them.
  - To undo a change that has already been committed and pushed, use `git revert <commitID>`. This will create a new commit that applies the inverse diff. Note that you still have to push this commit to publish it.
  - To throw away all changes that you have locally committed but not yet pushed, use `git reset --hard origin/master`. '''You will loose all your uncommitted and committed modifications.''' If that is not what you want, Git provides a variety of tools that allow you to change commits that you have not pushed yet (and theoretically also commits that have already been pushed, which will prevent you from pushing any changes again). Since this is an advanced topic it will not be covered here. As a pointer for further research, look for `git commit --amend` to change the topmost commit and `git rebase --interactive`, the so-called "interactive rebase", to change older commits.
+
 
 === Repository split === #reposplit
 
@@ -228,11 +165,73 @@
 ||tags                                     ||''annotated tags in the appropriate repository/-ies''            ||
 
 
+
+
+
+== Common `git` tasks while working with ports ==
+
+
+=== Checking out a working copy of the ports tree === #cloneports
+To get a working copy of the MacPorts ports tree to start changing ports, clone of copy of the repository:
+{{{
+git clone git at github.com:macports/ports.git # or
+git clone https://github.com/macports/ports.git # if SSH does not work on your network
+}}}
+
+This will give you the entire history of the ports tree, with the latest version being checked out in the filesystem.
+
+'''Note:''' If you intend to submit a pull request on GitHub to get your changes included in MacPorts, you may want to create a fork of the repository first. To do that, go to https://github.com/macports/ports/ and click the fork button at the top right. Then, run the command above, but use `<yourusername>/ports.git` instead of `macports/ports.git`.
+
+See the [#commit section on committing changes] to find out how to get your changes into the repository.
+
+
+
+
+
+== Common `git` tasks while working with MacPorts base ==
+
+
+=== Checking out a working copy of MacPorts base === #clone
+The source code of MacPorts itself is no longer managed in the same repository as all ports. Contrary to Subversion, checking out a sub-directory of a repository is not possible with Git. In order to avoid that all port maintainers have to clone the complete history of MacPorts base as well, the Subversion repository has been split into multiple separate repositories. MacPorts base is now available using
+{{{
+git clone git at github.com:macports/base.git # or
+git clone https://github.com/macports/base.git # if SSH does not work on your network
+}}}
+
+See the [#reposplit section on repository splitting during the export] to get an overview of where a path in the old Subversion history is now available in Git.
+
+
+=== Merge a single change from master into a release branch === #cherrypick
+The equivalent to Subversion's `svn merge -c <revision> .` is `git cherry-pick`. Use `git cherry-pick` to apply a single change from master to a release branch. To do this, look up the commit ID of the commit you want to pick:
+{{{
+git log
+# copy the commit ID
+}}}
+Switch to the target branch of the cherry pick:
+{{{
+git checkout release_2_3
+}}}
+Cherry-pick the commit. It is good practice to pass `-x` to `git cherry-pick`, which will automatically add a "Cherry picked from commit <commmitID>" line to the commit message of your cherry pick. You will have the option to modify the commit message, e.g. to describe why the backport was necessary.
+{{{
+git cherry-pick -x <commitID>
+}}}
+Finally, push the new commit using
+{{{
+git push origin <branchname>
+}}}
+
+
+
+
+
 == Tools == #tools
 
 - [https://git-scm.com/docs/gitk gitk] is a Tk-based graphical repository browser included with Git itself.
 - [http://gitx.frim.nl GitX] is a graphical repository browser designed for macOS. Unfortunately, our `GitX` port is [[ticket:42957|currently nonfunctional]].
 - [http://jonas.nitro.dk/tig Tig] is an ncurses-based interface, available from the `tig` port.
+
+
+
 
 
 == Learning Resources == #resources
-------8<------8<------8<------8<------8<------8<------8<------8<--------

--
Page URL: <https://trac.macports.org/wiki/WorkingWithGit>
MacPorts <https://www.macports.org/>
Ports system for OS X

This is an automated message. Someone added your email address to be
notified of changes on 'WorkingWithGit' page.
If it was not you, please report to .


More information about the macports-changes mailing list