FAQ
| This is a
LIVE
service |
Changelog
Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
DevOps Division Guidebook
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Information Services
DevOps
General Documentation
DevOps Division Guidebook
Commits
343de3e9
Commit
343de3e9
authored
3 years ago
by
Dr Rich Wareham
Browse files
Options
Downloads
Patches
Plain Diff
add documentation on merging repo histories
parent
a6525f16
No related branches found
No related tags found
1 merge request
!110
add documentation on merging repo histories
Pipeline
#141825
passed
3 years ago
Stage: test
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
docs/workflow/git-tricks.md
+67
-0
67 additions, 0 deletions
docs/workflow/git-tricks.md
mkdocs.yml
+1
-0
1 addition, 0 deletions
mkdocs.yml
with
68 additions
and
0 deletions
docs/workflow/git-tricks.md
0 → 100644
+
67
−
0
View file @
343de3e9
# Git tips and tricks
This page collects various
`git`
tips and tricks which may be useful.
## Merging history from two repos
### Scenario
A new version of a service or a new deployment of an existing service has been
developed in a new repository. We have moved over to using that repository as
the source of truth but want the history of the old respository present in the
new one.
### Example
The
[
IdP frontend
container
](
https://gitlab.developers.cam.ac.uk/uis/devops/raven/shib-cloud/idp-frontend-container
)
for Shibboleth is now the canonical source of configuration. We want to merge
configuration from the
[
previous Ansible
configuration
](
https://gitlab.developers.cam.ac.uk/uis/devops/raven/ansible-shibboleth
)
.
### Recipe
Move to your local clone of
https://gitlab.developers.cam.ac.uk/uis/devops/raven/shib-cloud/idp-frontend-container
and add a new remote:
```
console
$
cd
path/to/idp-frontend-container
$
git checkout master
# checkout the master branch
$
git pull
# make sure we're up to date
$
git remote add other git@gitlab.developers.cam.ac.uk:uis/devops/raven/ansible-shibboleth.git
$
git fetch other
```
The other repository's master branch is now available at
`other/master`
. Create
a new branch which will be used to open a MR with the new history:
```
console
$
git checkout
-b
branch-for-mr
```
We want to _merge_ the histories of the old repo into the new but not change any
of the existing files. This is an example of a merge _strategy_. Git calls this
strategy "ours". Perform the merge:
```
console
$
git merge
--strategy
ours other/master
```
Check that no changes have been made by computing a diff against master:
```
console
$
git diff master
# should produce no output
```
Check that the other repo's history is present:
```
console
$
git log
# should see some comits from the other repo
```
If all is good, push to upstream and open a MR:
```
console
$
git push
-u
origin branch-for-mr
```
This diff is collapsed.
Click to expand it.
mkdocs.yml
+
1
−
0
View file @
343de3e9
...
...
@@ -29,6 +29,7 @@ nav:
-
workflow/onboarding.md
-
workflow/pypi.md
-
workflow/credentials-and-secrets.md
-
workflow/git-tricks.md
-
'
Best
Practice'
:
-
best-practice/index.md
-
best-practice/git.md
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment