Versions Compared

Key

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

...

Any changes that they wish to contribute back to the upstream repository can be done in the form of a Pull Request.

Undoing your Last Commit

If you accidentally commit something you ought not have, but have not yet pushed the commit to your personal fork, run the following command to undo the commit:

Code Block
languagebash
git reset HEAD^

The ^ tells git to reset to "the previous commit before head." You can chain together multiple ^'s to go back to the nth previous commit, but I would not recommend this unless you know what you are doing.

Contribute Back with Pull Requests

...

In the description, I normally like to link to the JIRA ticket as well, if one exists.

...

Resolving Merge Conflicts

Case: Say you want to make a new addition to the code.

So you follow the workflow described above, create a fork and maybe even a new branch to avoid collisions.

...

(You are creating separate branches for each of your features, aren't you? This minimizes the size of potential conflicts by isolating each set of related changes. See Recommendations below.)

Pull from Upstream

On your local copy, pull from upstream to grab any changes to the upstream repo:

Code Block
languagebash
$ git pull upstream master
remote: Counting objects: 4, done.
remote: Compressing objects: 100% (1/1), done.
remote: Total 4 (delta 3), reused 4 (delta 3), pack-reused 0
Unpacking objects: 100% (4/4), done.
From https://github.com/nds-org/ndslabs-specs
 * branch            master     -> FETCH_HEAD
 * [new branch]      master     -> upstream/master
Auto-merging clowder/clowder.json
CONFLICT (content): Merge conflict in clowder/clowder.json
Automatic merge failed; fix conflicts and then commit the result.

Notice the line starting with CONFLICT, which indicates that you will manually need to fix this file.

Locate Offending Conflicts

Open the file in your favorite editor and you should see the conflict(s) surrounded by > and <:

Code Block
languagejs
.....
        {
            "name": "RABBITMQ_EXCHANGE",
            "value": "clowder",
            "canOverride": false
        },
        {
<<<<<<< HEAD
            "name": "TOOLMANAGER_URI",
            "value": "localhost:8082",
=======
            "name": "TOOLMGR_URI",
            "value": "http://localhost:8082",
>>>>>>> 807f37cbf505e06469a7b54429be5e3a60dd26d3
            "label": "ToolServer address",
            "canOverride": true
        }
    ],
    "ports": [
        {
.....

<<<<<<< HEAD indicates the HEAD of your current local working copy ("your" modifications)

>>>>>>> COMMIT SHA HASH indicates the SHA hash of the conflicting commit ("their" modifications)

Resolve Any Conflicts

Edit each file appropriately to resolve the merge conflict(s).

Simply remove any excess bits and retain only the file that you wish to commit:

Code Block
languagejs
.....
        {
            "name": "RABBITMQ_EXCHANGE",
            "value": "clowder",
            "canOverride": false
        },
        {
            "name": "TOOLMANAGER_URI",
            "value": "http://localhost:8082",
            "label": "ToolServer address",
            "canOverride": true
        }
    ],
    "ports": [
        {
.....

Tell Git that you have Resolved the Conflicts

Now re-add any conflicting files to git's index.

This will mark the conflict as resolved, and stage the files for commit.

Now you should be able to commit to your local copy, then push to your personal fork:

Code Block
languagebash
$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
You have unmerged paths.
  (fix conflicts and run "git commit")
Unmerged paths:
  (use "git add <file>..." to mark resolution)
	both modified:   clowder/clowder.json
no changes added to commit (use "git add" and/or "git commit -a")


$ git add clowder/clowder.json 
 
$ git commit -a -m "Fixed merge conflict"
[master e09f5a2] Fixed merge conflict
 1 file changed, 1 insertion(+), 1 deletion(-)


$ git push origin master
Username for 'https://github.com': your-git-username
Password for 'https://your-git-username@github.com': 
Counting objects: 4, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (4/4), 366 bytes | 0 bytes/s, done.
Total 4 (delta 3), reused 0 (delta 0)
To https://github.com/your-git-username/ndslabs-specs.git
   c241a36..e09f5a2  master -> master

 

 

...

Verify that Conflict is Resolved

You should now see that your outstanding Pull Request, if you made one, has been updated to include your newly pushed commit.

Hopefully the indicator changed from gray (conflict) to green (mergeable), and your conflict has been resolved:

Image Added

NOTE: You may need to perform these steps multiple times to work out all merge conflicts.

With a fully resolved branch, pulling should yield the following messages:

Code Block
languagebash
$ git pull upstream master
From https://github.com/nds-org/ndslabs-specs
 * branch            master     -> FETCH_HEAD
Already up-to-date.

Recommendations

Segment Feature Changes to Different Branches

...

NOTE: In general, we tend to name branches after the key of their associated JIRA tickets. For example: NDS-101

Undoing your Last Commit

Locally

If you accidentally commit something you ought not have, but have not yet pushed the commit to your personal fork, run the following command to undo the commit:

Code Block
languagebash
git reset HEAD^

The ^ tells git to reset to "the previous commit before head." You can chain together multiple ^'s to go back to the nth previous commit, but I would not recommend this unless you know what you are doing.

On Personal Fork

If you have already pushed the change to your personal fork, then you may be out of luck.

If the mistaken change that you made on a separate branch, you can delete the branch from your GitHub.com fork, revert the change locally and then re-push the branch.

If you made the mistaken change to master, then the only option to remove it may be to delete your entire personal fork and re-fork the upstream repo.

WARNING: Make sure to have any outstanding Pull Requests MERGED before deleting your personal fork, or your changes may get lost.