/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the Qt Creator documentation.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU Free Documentation License Usage
** Alternatively, this file may be used under the terms of the GNU Free
** Documentation License version 1.3 as published by the Free Software
** Foundation and appearing in the file included in the packaging of
** this file. Please review the following information to ensure
** the GNU Free Documentation License version 1.3 requirements
** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
**
****************************************************************************/

// **********************************************************************
// NOTE: the sections are not ordered by their logical order to avoid
// reshuffling the file each time the index order changes (i.e., often).
// Run the fixnavi.pl script to adjust the links to the index order.
// **********************************************************************

/*!
    \contentspage {Qt Creator Manual}
    \previouspage creator-vcs-cvs.html
    \page creator-vcs-git.html
    \nextpage creator-vcs-mercurial.html

    \title Using Git

    Git is a fast decentralized version control system. Git is available
    for Windows, Linux, and \macos.

    You can use the \l{http://code.google.com/p/gerrit/}{Gerrit} code review
    tool for projects that use Git.

    \section1 Using Git for Windows

    If you configure Git for use with \c {git bash}, only, and use SSH
    authorization, Git looks for the SSH keys in the directory where the
    \c HOME environment points to. The variable is always set by \c {git bash}.

    However, the variable is typically not set in a Windows command prompt. When
    you run Git from a Windows command prompt, it looks for the SSH keys in its
    installation directory, and therefore, the authorization fails.

    You can set the \c HOME environment variable from \QC. Select
    \uicontrol Tools > \uicontrol Options > \uicontrol {Version Control} >
    \uicontrol Git, and then select the
    \uicontrol {Set "HOME" environment variable} check box. \c HOME is
    set to \c %HOMEDRIVE%%HOMEPATH% when the Git executable is run and
    authorization works as it would with \c {git bash}.

    \section1 Reverting Changes Using Git

    The Git version control system has an index that is used to stage
    changes. The index is committed on the next commit. Git allows you to revert
    back to the state of the last commit as well as to the state staged in the
    index.

    \list

        \li \uicontrol Git > \uicontrol {Current File} >
            \uicontrol{Undo Unstaged Changes} reverts all changes and resets the
            current file to the state of the index.

        \li \uicontrol Git > \uicontrol {Current File} >
            \uicontrol {Undo Uncommitted Changes} reverts all changes,
            discarding the index. This returns the current file to the state it
            was in right after the last commit.

        \li \uicontrol Git > \uicontrol {Local Repository} > \uicontrol Reset
            opens a dialog where you can select the SHA-1 to reset the working
            directory to. This is useful after applying patches for review, for
            example. You can choose between a \uicontrol Soft reset that does
            not touch the index file nor the working tree at all, a
            \uicontrol Hard reset that discards all changes to tracked files in
            working tree, and a \uicontrol Mixed reset that resets HEAD and the
            index (nothing remains staged) without touching the working
            directory.

    \endlist

    \section1 Working with the Current File

    In addition to the standard version control system functions, you can
    select \uicontrol Tools > \uicontrol Git > \uicontrol {Current File} >
    \uicontrol {Stage File for Commit} to mark a new or modified file for
    committing to the repository.

    To undo this function, select \uicontrol {Unstage File from Commit}.

    \section1 Working with the Current Project

    In addition to the standard version control system functions, you can
    select \uicontrol Tools > \uicontrol Git > \uicontrol {Current Project} >
    \uicontrol {Clean Project}
    to clean the working directory. All files that are not under version control
    are displayed in the \uicontrol {Clean Repository} dialog. Ignored files are
    deselected by default. Select the files to delete and click
    \uicontrol Delete.

    \section1 Working with Local Repositories

    In addition to the standard version control system functions, you can
    select \uicontrol Tools > \uicontrol Git > \uicontrol {Local Repository} >
    \uicontrol Clean to clean the repository.

    To apply latest changes to the last commit, select \uicontrol Tools >
    \uicontrol Git > \uicontrol {Local Repository} >
    \uicontrol {Amend Last Commit}. You can also edit the commit message.

    To amend an earlier comment in a series of related commits, select
    \uicontrol Tools > \uicontrol Git > \uicontrol {Local Repository} >
    \uicontrol {Fixup Previous Commit}. This operation is done using interactive
    rebase. In case of conflicts, a merge tool is suggested.

    To change a series of commits in the local repository, select
    \uicontrol Tools > \uicontrol Git > \uicontrol {Local Repository} >
    \uicontrol {Interactive Rebase}. You can reorder or discard commits, squash
    them into a single commit, or edit the commit messages.

    The following sections describe how to manage local and remote branches,
    apply patches, and use stashes.

    \section2 Working with Branches

    To work with Git branches, select \uicontrol Tools > \uicontrol Git >
    \uicontrol {Local Repository} > \uicontrol {Branches}. The checked out
    branch is shown in bold and underlined in the list of branches. Double-click
    branch names to edit them.

    \image qtcreator-vcs-gitbranch.png "Branches dialog"

    The following operations are supported:

    \table
        \header
            \li Menu Item
            \li Description
        \row
            \li \uicontrol{Refresh}
            \li Refresh the list of branches.
        \row
            \li \uicontrol{Add}
            \li Create new tracking and non-tracking branches.
        \row
            \li \uicontrol{Remove}
            \li Remove a local branch. You cannot delete remote branches.
        \row
            \li \uicontrol Rename
            \li Rename a local branch.
        \row
            \li \uicontrol{Checkout}
            \li Check out the selected branch and make it current. You can stash
                changes you have made to tracked files.
        \row
            \li \uicontrol{Diff}
            \li Show the differences between the selected and the current
                branch.
        \row
            \li \uicontrol{Log}
            \li Show the changes in a branch.
        \row
            \li \uicontrol Merge
            \li Join the development histories in two branches together.

                If the commit you are merging can be reached by following the
                first commit's history, there is no divergent work to merge
                together. To allow Git to move the branch pointer forward,
                select \uicontrol {Fast-Forward}. If you do not want to
                fast-forward the branch, select \uicontrol {No Fast-Forward}.
        \row
            \li \uicontrol Rebase
            \li Copy local commits to the updated upstream head.
        \row
            \li \uicontrol Reset
            \li Hard reset the active branch to the selected branch.
        \row
            \li \uicontrol {Cherry Pick}
            \li Cherry pick the top commit from the selected branch.
        \row
            \li \uicontrol Track
            \li Set the current branch to track the selected one.
    \endtable

    \section2 Applying Patches

    Patches are rewriting instructions that can be applied to a set of files.
    To apply a patch file that is open in \QC, select \uicontrol Tools >
    \uicontrol Git > \uicontrol {Local Repository} > \uicontrol Patch >
    \uicontrol {Apply from Editor}.

    To select the patch file to apply from the file system, select
    \uicontrol {Apply from File}.

    \section2 Using Stashes

    With Git, you can put your current set of changes onto a virtual shelf
    called a \e stash. Stashes are useful, for example, to put aside a set of
    changes to work on higher priority tasks or to pull in new chages from
    another repository.

    To stash all local changes, select \uicontrol Tools > \uicontrol Git >
    \uicontrol {Local Repository} > \uicontrol Stash > \uicontrol Stash. The
    working copy is reset to the state it had after the last commit. To save the
    current state of your unstaged files and reset the repository to its staged
    state, select \uicontrol {Stash Unstaged Files}.

    To display a dialog that shows all known stashes with options to restore,
    display or delete them, select \uicontrol Stashes.

    To save a snapshot of your current work under a name for later reference,
    select \uicontrol {Take Snapshot}. The working copy is unchanged. For
    example, if you want to try something and find out later that it does not
    work, you can discard the changes and return to the state of the snapshot.

    To remove a single stashed state from the stash list and apply it on top of
    the current working tree state, select \uicontrol {Stash Pop}.

    \section1 Applying Actions to Commits

    To browse a directory or the commit history and to apply actions on the
    commits, select \uicontrol Tools > \uicontrol Git >
    \uicontrol {Actions on Commits}. You can checkout, revert, or cherry-pick
    commits or view them in the diff editor.

    \image creator-git-commit-actions.png "Select a Git Commit dialog"

    \section1 Working with Remote Repositories

    In addition to the standard version control system functions, you can
    select \uicontrol Tools > \uicontrol Git > \uicontrol {Remote Repository} >
    \uicontrol Pull topull changes from the remote repository. If there are
    locally modified files, you are prompted to stash the changes. Select
    \uicontrol Tools > \uicontrol Options > \uicontrol {Version Control} >
    \uicontrol Git and then select the \uicontrol {Pull with rebase} check box
    to perform a rebase operation while pulling.

    \section2 Managing Remote Repositories

    To manage remote repositories available in Git, select \uicontrol Tools >
    \uicontrol Git > \uicontrol {Remote Repository} >
    \uicontrol{Manage Remotes}. Double-click the names and URLs of the remote
    repositories to edit them.

    The following operations are supported:

    \table
        \header
            \li Menu Item
            \li Description
        \row
            \li \uicontrol{Refresh}
            \li Refresh the list of remote repositories.
        \row
            \li \uicontrol{Add}
            \li Add a new remote repository.
        \row
            \li \uicontrol{Fetch}
            \li Fetch all the branches and change information from a remote
                repository.
        \row
            \li \uicontrol Push
            \li Push committed changes to the remote repository.
        \row
            \li \uicontrol{Remove}
            \li Remove a remote repository.

    \endtable

    \section2 Using Git with Subversion

    You can use Git as a client for a Subversion server. To fetch changes from a
    Subversion repository to a Git repository, select \uicontrol Tools >
    \uicontrol Git > \uicontrol {Remote Repository} > \uicontrol Subversion >
    \uicontrol Fetch.

    To view the Git Subversion log, select \uicontrol Log.

    \section2 Reviewing Code with Gerrit

    If your Git project uses Gerrit for code reviews, you can view your changes
    in \QC.

    To push committed changes to Gerrit, select \uicontrol Tools >
    \uicontrol Git > \uicontrol {Remote Repository} >
    \uicontrol {Push to Gerrit}.

    To view the same information about each change as in the Gerrit
    web interface, select \uicontrol Tools > \uicontrol Git >
    \uicontrol {Remote Repository} > \uicontrol Gerrit.

    \image qtcreator-gerrit.png

    To view details of the selected change, select \uicontrol Show.

    To cherry-pick the selected change to the local repository, select
    \uicontrol {Cherry Pick}. To remove the change after testing it, select
    \uicontrol Tools > \uicontrol Git > \uicontrol {Local Repository} >
    \uicontrol Reset. In the \uicontrol {Undo Changes to} dialog, select the
    state to reset the working directory to, and then select \uicontrol OK.

    To check out the change in a headless state, select \uicontrol Checkout.

    To refresh the list of changes, select \uicontrol Refresh.

    The \uicontrol Remote field lists the remotes of the current repository that
    are detected as Gerrit servers. Select \uicontrol Tools > \uicontrol Options
    > \uicontrol {Version Control} > \uicontrol Gerrit to specify a fallback
    connection to a Gerrit server over SSH. The Gerrit REST interface and the
    \l{https://curl.haxx.se/}{curl} tool are used for HTTP connections.

    Select the \uicontrol HTTPS check box to prepend \c https to the Gerrit URL
    if Gerrit does not provide it.

    \image qtcreator-gerrit-options.png

    \section1 Working with Git Tools

    To start a graphical interface to Git, select \uicontrol Tools >
    \uicontrol Git > \uicontrol {Git Tools} > \uicontrol {Git Gui}.

    \note On \macos, the default Git installation does not contain Git Gui. To
    use Git Gui, install it separately. To start Git Gui from \QC, select
    \uicontrol Preferences > \uicontrol {Version Control} > \uicontrol Git, and
    set the path to the environment that contains Git Gui in the
    \uicontrol {Prepend to PATH} field.

    To start the commit viewer for Git, select \uicontrol Tools >
    \uicontrol Git > \uicontrol {Git Tools} > \uicontrol Gitk. You can also
    start the tool to view commits in the current document or in the folder that
    contains the current document. To specify arguments for running Gitk, select
    \uicontrol Tools > \uicontrol Options > \uicontrol {Version Control} >
    \uicontrol Git.

    To use some other application for viewing Git history, such as GitX or
    QGit viewer, select \uicontrol Tools > \uicontrol Options >
    \uicontrol {Version Control} > \uicontrol Git and specify the path to the
    application executable in the \uicontrol {Command} field. To start the
    application, select \uicontrol Tools > \uicontrol Git
    > \uicontrol {Git Tools} > \uicontrol {Repository Browser}.

    To resolve merge conflicts, select \uicontrol Tools > \uicontrol Git >
    \uicontrol {Git Tools} > \uicontrol {Merge Tool}.
*/
