CONTROLLED DATA
Leidos Proprietary - US Citizens ONLY
The information contained herein is proprietary to Leidos, Inc. It may not be used, reproduced, disclosed, or exported without the written approval of Leidos.
Sometimes we don't want to put our whole repository up into the ECR. This could be for a variety of reasons. Perhaps part of our repository is experimental and not ready for sharing, or there might be customer related information, or production keys and things like that.
If this is the case for you, then there is still a way that you can share part of your repo, and maintain updates - its a little more work when you share updates, but its not too difficult.
The basic idea is this:
- Copy the source you want to share to a new location. If you can preserve the directory layout, then that will make things easier, when you want to share updates.
- Perform a git init in the top level folder of your copied source
- Add all your code with git add --all or git add .
- Add the new remote from ECR ex: git remote add origin ssh://git@ecr.sdo.leidos.com:7998/<project key>/<repo name>.git
- Commit your code to master git commit -a -m "initial update for sharing"
- Then push the code to ECR: git push origin master
- Now, to work nicely within ECR, create the community branch
- git checkout -b community
- git push origin community
Thats it. You have now shared your partial set of code into ECR. (don't forget to add your required docs!)
Now suppose some time in the future, that you have a change that you would like to send to ECR. Since your share repository, and you original repository don't share a git commit history, you can't do a simple git push ecr... You will need to create a patch, and then use the patch to update your share repo.
So, how do we create a patch file. That depends on your scenario. I have captured 3 different scenarios here. You have created a branch from master or develop, in your original code, and you want to create a patch from that branch, before its merged back into the baseline. You want simply create a patch from the last N commits that have been made against a branch, or you want to include the data from a particular commit point (hash). Lets dive into all three scenarios.
Preparing a patch
Create a patch from a branch not yet merged
This is the easiest one to implement. It does assume that your code has not yet been merged, and in that case we can let git do all the work. Lets say your changes are on a branch called my-new-feature, and that brach came from the develop branch.
git checkout my-new-feature git format-patch develop --stdout > my-new-feature.patch
Create a patch from the last N commits
Now lets assume that you code has already been merged back to develop, so you need to pull off a few commits and make a patch from those. You can use git log --pretty=oneline -N where N is the number commits you want to look at.
Here is an example from the EDR Docs project.
git log --pretty=oneline -5 a349e134447a68229669bde94f817bc07dd93e6a (HEAD -> master, dev/master) rearranged kb article layout 12b46ad325bc5ae1d628c13f4445c07a4fc7a825 updated with links to KB articles and example README b2a031f0425a73ef6d1dd5c67511576df137c861 reorganized the sidebar 4d04d6215d0d762d3b513005b07633dd596f609b updated spreadsheet styling 26497d0d795519fb4490819cbb1df1399659cddf fixed a spelling error in the READMECreate a branch from a particular commit
Here are the last 5 commits. Lets say that I want to include the changes from the reorganized the sidebar change, up to the latest change in my patch. That change is 3 changes back so I can just do this:
git format-patch HEAD~3..HEAD --stdout > last3Changes.patch
Create a patch from based on a commit hash
Lastly, what if I know the commit hash, and want to take all the changes from that hash or from that hash back in time. I can do that by looking at the commit log (see the git log from above), and then deciding how may preceding changes to take. Lets say, I want the reorganized the sidebar change, along with the preceding two changes. Lets say I want 2 total changes.
git format-patch -2 b2a031f0425a73ef6d1dd5c67511576df137c861 --stdout > sidebarAndSpreadsheet.patch
Applying a patch
Now that I have my patch file, I head on over to my ECR repo and apply the patch. For this case, lets say I am applying the sidebarAndSpreadsheet.patch.
git checkout master git am < sidebarAndSpreadsheet.patch
Once the patch is applied, just commit the changes, and push it up to ECR.
git commit -am -m "updates from base project" git push origin master git checkout community git pull origin master git push origin community
One more thing, if you are taking in changes from the community branch, you might want to add a develop branch in between master and community - but I will leave that up to you.