Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Before reviewing this page, you should be familiar with concepts of version control and distributed version control systems. See /wiki/spaces/CONNECTWIKI/pages/8585251 for information and links.

Cloning the Repository

  • How do I clone the CONNECT git repository?

    Code Block
    git clone https://github.com/CONNECT-Solution/CONNECT <desired path>
    


Branching and Tagging

...

  • How do I work with a tag based off of a branch (e.g. 3.2.2_RC2 tag based off of 3.2.2 branch)?

    Code Block
    git checkout 3.2.2      # checkout base branch
    git pull                # get latest remote base branch
    git checkout 3.2.2_RC2  # checkout tag
    


History

  • How do I view the git history of a file?

    Code Block
    git log --follow EntityNotifySoapHeaderHandler.xml
    


...

^ (one previous commit) shortcut.

Cleaning

  • How do I clean up all the unknown files in my workspace?

    Code Block
    git clean -f -d
    git clean -f -d -X (remove ignored files as well)
    


  • How do revert all my changes?

    Note
    titleWarning

    This will delete all your changes as no backups are created!


    Code Block
    git reset --hard
    


  • To revert a single file or deleted directory, do:

    Code Block
    git checkout HEAD <FILE>
    


Reverting

  • Halp! I accidentally committed and pushed a file to github! How do I revert it?
    Like subversion, you have to revert the file locally and then commit it. The <commit-ref> in the command below can be the SHA-1 value or the HEAD

...

  • Sample revert

    Code Block
    akong@plain:~/Workspace/connect/Current/Product/SoapUI_Test/ValidationSuite$ git checkout 4cf2f12f9659c4022d4c0740955da81b6ee1fb93 -- 2-EndToEndSelfTest_g1-soapui-project.xml
    
    akong@plain:~/Workspace/connect/Current/Product/SoapUI_Test/ValidationSuite$ git status
    # On branch 3.3.1
    # Changes to be committed:
    #   (use "git reset HEAD <file>..." to unstage)
    #
    #    modified:   2-EndToEndSelfTest_g1-soapui-project.xml
    #
    # Untracked files:
    #   (use "git add <file>..." to include in what will be committed)
    #
    #    ../../Production/global-groovy.log
    #    ../../Production/soapui-errors.log
    #    ../../Production/soapui.log
    


Diff-ing

  • How do I see what changes there are in my current working set?

    Code Block
    git status
    


  • Show all files that have been modified and not staged as a list

    Code Block
    git diff --stat
    


  • Diff between what is staged and what has been committed

    Code Block
    git diff --staged
    


  • Ignore blank and white spaces diff

    Code Block
    git diff -b -w --staged
    


  • Filter the diff: ignore deleted files

    Code Block
    git diff --diff-filter=ACMRTUXB --staged
    


  • How do I see the diff between my branch against a previous revision

    Code Block
    git diff HEAD^ HEAD
    

    Each ^ represents one previous revision, so HEAD^^ means two previous revisions. Equivilant to ^ is ~. HEAD~ is the same as HEAD^, and HEAD~3 is the same as HEAD^^^.

Stashing

  • Stash all your changes. This will stash all your modifications in the stash stack and revert back your branch to its original state.

    Code Block
    git stash save "GATEWAY-123: Stuff"
    


...

  • Drops a stash from the stack. This will delete it.

    Code Block
    git stash drop stash@{0}
    


  • Show a diff of a particular stash from the stack.

    Code Block
    git stash show -p stash@{0}
    


Committing and Pushing to Github

Note
titleEmpty Directories

Git will not push an empty folder into the repository, so add an empty .gitignore inside if you need them.

  • How do I get the latest from remote? This will merge the changes from the remote repository to your branch.

    Code Block
    git pull
    


  • How do I stage all my modified files for later commit?

    Code Block
    git add .
    git add -u (updates)
    


  • How do I stage a subset of my modified files for later commit?

    Code Block
    git add <file1> <file2> <etc.>
    


  • How do I commit everything that has been staged?

    Code Block
    git commit -m "commit message including Jira issue number"
    


  • How do I push my commits to the remote repository?

    Code Block
    git push origin <remote branch name>
    


Sample Push to Github

Code Block
akong@plain:~/Workspace/connect/Current/Product$ git status
# On branch 3.3.1
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#    modified:   Production/Common/CONNECTCoreLib/src/main/java/gov/hhs/fha/nhinc/docregistry/adapter/AdapterComponentDocRegistryOrchImpl.java
#    modified:   Production/Common/CONNECTCoreLib/src/main/java/gov/hhs/fha/nhinc/docrepository/adapter/dao/DocumentDao.java
#    modified:   Production/Common/CONNECTCoreLib/src/main/java/gov/hhs/fha/nhinc/docrepository/adapter/model/DocumentQueryParams.java
#    new file:   Production/Common/CONNECTCoreLib/src/test/java/gov/hhs/fha/nhinc/docregistry/adapter/AdapterComponentDocRegistryOrchImplTest.java
#    modified:   SoapUI_Test/ValidationSuite/2-EndToEndSelfTest_g0-soapui-project.xml
#    modified:   SoapUI_Test/ValidationSuite/properties/2-EndToEndSelfTest_g0-soapui-project.properties
#

akong@plain:~/Workspace/connect/Current/Product$ git commit -m "GATEWAY-1952: Added ondemand support for QD/DocRegistry adapter"
[3.3.1 04b656e] GATEWAY-1952: Added ondemand support for QD/DocRegistry adapter
 6 files changed, 392 insertions(+), 83 deletions(-)
 create mode 100644 Product/Production/Common/CONNECTCoreLib/src/test/java/gov/hhs/fha/nhinc/docregistry/adapter/AdapterComponentDocRegistryOrchImplTest.java

akong@plain:~/Workspace/connect/Current/Product$ git status
# On branch 3.3.1
# Your branch is ahead of 'origin/3.3.1' by 1 commit.
#
nothing to commit (working directory clean)

akong@plain:~/Workspace/connect/Current/Product$ git push origin 3.3.1
Username:
Password:
Counting objects: 66, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (27/27), done.
Writing objects: 100% (36/36), 7.43 KiB, done.
Total 36 (delta 16), reused 0 (delta 0)
To https://github.com/CONNECT-Solution/CONNECT.git
   1b68a6d..04b656e  3.3.1 -> 3.3.1

Git Configuration

Git configuration can occur in three separate files.

...

On Windows systems, Git looks for the .gitconfig file in the $HOME directory (C:Documents and Settings$USER for most people). It also still looks for /etc/gitconfig, although it’s relative to the MSys root, which is wherever you decide to install Git on your Windows system when you run the installer.

Creating Aliases

This section details how to create aliases in git. Aliases are useful for common commands such as checkout, status, and branch.

...

Here is a list of common shortcuts:
co = checkout
br = branch
ci = commit
st = status
branches = branch

Commits and Rebasing

How do I update my branch with the latest from origin/CONNECT_integration AND push it to my fork?

Code Block
git checkout my-feature
git fetch origin
git merge origin/CONNECT_integration
git push my-alias <fork's branch>

How do I create a local branch that is tracking another branch from somebody else's fork?

Code Block
git remote add <fork>
git checkout -b yourNewBranch
git pull <fork> <fork's branch>

How do I rebase?

In the example below, we rebase the my-feature branch with the CONNECT_integration before we push. This will make your history look like you did your changes from the latest CONNECT_integration head instead of the one that you branched off from when you created your my-feature branch.

...