git
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| git [2024/08/31 05:23] – [Move a Superproject to a New Server] jhagstrand | git [2024/10/10 05:55] (current) – [worktree] jhagstrand | ||
|---|---|---|---|
| Line 5: | Line 5: | ||
| Written by Linus Torvalds to replace svn and cvs. | Written by Linus Torvalds to replace svn and cvs. | ||
| + | todo: | ||
| + | * streamline the submodule section | ||
| + | * streamline the internals section | ||
| + | * coordinate the " | ||
| + | * coordinate workflow section with " | ||
| =====Overview===== | =====Overview===== | ||
| Components of git: | Components of git: | ||
| * repository | * repository | ||
| - | * remote | ||
| * branch | * branch | ||
| * commit | * commit | ||
| Line 20: | Line 24: | ||
| * working copy - sometimes used to refer to the current worktree | * working copy - sometimes used to refer to the current worktree | ||
| * workflow - the procedures and conventions used by a development team | * workflow - the procedures and conventions used by a development team | ||
| + | |||
| + | More: | ||
| * index - ? | * index - ? | ||
| * HEAD - ? | * HEAD - ? | ||
| * detached head - ? | * detached head - ? | ||
| + | * commit-ish | ||
| + | * SHA-1 value | ||
| + | * HEAD | ||
| + | * refs | ||
| + | * branch = ref | ||
| + | * Three object types: blobs, trees, commits | ||
| + | * fourth: tags | ||
| + | * refs: branch, tag, remote | ||
| ====repository==== | ====repository==== | ||
| Line 106: | Line 119: | ||
| You can push, you can pull. | You can push, you can pull. | ||
| You cannot status, merge, commit, diff, etc, because these commands act on the paired worktree. | You cannot status, merge, commit, diff, etc, because these commands act on the paired worktree. | ||
| + | |||
| + | ==== push vs pull ==== | ||
| + | |||
| + | git push - pushes commits from one repo to another\\ | ||
| + | git pull - pulls changes and merges them into a local worktree | ||
| + | |||
| + | if we wanted to do a pull, we could pull into webprod or webdev, then push from there to voycgit | ||
| + | |||
| + | ==== merge vs rebase ==== | ||
| + | |||
| + | if development is ongoing in the master branch | ||
| + | while some special feature development is going on in the feature branch | ||
| + | |||
| + | when you eventually merge the feature back into master, do a merge, to maintain the true history | ||
| + | |||
| + | in the the meantime, to bring master changes into the feature, do a rebase, | ||
| + | handle the conflicts now, so the future feature merge will run without conflicts | ||
| + | |||
| + | handle conflicts conflicts in the feature branch, not when attempting the final feature merge | ||
| + | |||
| Line 166: | Line 199: | ||
| In .gitconfig, add | In .gitconfig, add | ||
| [core] whitespace = -trailing-space, | [core] whitespace = -trailing-space, | ||
| + | |||
| + | |||
| + | ===== superproject and submodule ===== | ||
| ====Add submodule to super-project==== | ====Add submodule to super-project==== | ||
| Line 174: | Line 210: | ||
| git submodule update --init | git submodule update --init | ||
| git submodule foreach git pull origin master | git submodule foreach git pull origin master | ||
| + | ====submodules==== | ||
| - | ===== superproject | + | In the listings above jslib shows as an empty folder in the worktree, |
| + | and as a commit in the .git database.\\ | ||
| + | That is the commit that was originally pulled into this super-project. | ||
| + | |||
| + | |||
| + | git submodule update | ||
| + | This gets the url from .git/config [jslib] section. | ||
| + | And it gets the commit | ||
| + | When we do a git | ||
| + | |||
| + | ==all-in-one== | ||
| + | git clone --recurse-submodules https: | ||
| + | |||
| + | Does the clone and then does a | ||
| + | git submodule | ||
| + | |||
| + | |||
| + | ====Move a Superproject to a New GitServer==== | ||
| + | |||
| + | For example, we recently moved from github to gitlab. | ||
| + | |||
| + | A superproject contains submodules.\\ | ||
| + | Each submodule is identified by name, path, url, and commit-ish.\\ | ||
| + | You specify the name, path and url in the .gitmodules file.\\ | ||
| + | Git retains the commit-ish in the database, as you can see with '' | ||
| + | |||
| + | **Step 1.** manually edit the .gitmodules file.\\ | ||
| + | Here we specify the new server url. | ||
| + | |||
| + | **Step 2.** '' | ||
| + | This copies the changes in .gitmodules into the .git/config file. | ||
| + | |||
| + | **Step 3.** '' | ||
| + | This changes the remotes in the submodules. | ||
| + | |||
| + | **Step 4.** '' | ||
| + | This pulls a version of submodule jslib into the jslib folder, \\ | ||
| + | using the url found in .git/config and the jslib commit-ish found in the layer/.git database. | ||
| + | This version may not be the latest, and therefore we continue with step 4. | ||
| + | |||
| + | **Step 5.** '' | ||
| + | This pulls the latest commit from the jslib/ | ||
| + | |||
| + | **Step 6.** Add, commit and push the layout superproject. | ||
| + | $ git status | ||
| + | modified: | ||
| + | modified: | ||
| + | |||
| + | git add . | ||
| + | git commit -m 'Pull latest submodules' | ||
| + | git push origin master | ||
| + | ==== overview ==== | ||
| A superproject is one that has submodules. | A superproject is one that has submodules. | ||
| The submodules are listed in .gitmodules file of the superproject. | The submodules are listed in .gitmodules file of the superproject. | ||
| Line 386: | Line 474: | ||
| ====Forking Workflow==== | ====Forking Workflow==== | ||
| Fundamentally different than the other workflows discussed in this tutorial. Instead of using a single server-side repository to act as the “central” codebase, it gives every developer a server-side repository. This means that each contributor has not one, but two Git repositories: | Fundamentally different than the other workflows discussed in this tutorial. Instead of using a single server-side repository to act as the “central” codebase, it gives every developer a server-side repository. This means that each contributor has not one, but two Git repositories: | ||
| + | |||
| + | ===== Protocol ===== | ||
| + | |||
| + | Three choices: ssh, xttps, git. | ||
| + | |||
| + | $ git clone ssh:// | ||
| + | $ git clone xttps:// | ||
| + | |||
| + | The git protocol is a daemon that ships with git. It is similar to ssh but has no authentication and no encryption. | ||
| =====Web Access===== | =====Web Access===== | ||
| + | |||
| ====HTML Interface==== | ====HTML Interface==== | ||
| ^ product | ^ product | ||
| Line 399: | Line 497: | ||
| | github | | github | ||
| | gitlab | | gitlab | ||
| - | |||
| - | ==== Repository Clone Name Format ==== | ||
| - | |||
| - | $ git clone ssh:// | ||
| - | $ git clone xttps:// | ||
| - | |||
| =====.git Folder===== | =====.git Folder===== | ||
| Line 499: | Line 591: | ||
| 24cb5418f6fcc6d2ddd292593d412ec760b57028 Initial file load | 24cb5418f6fcc6d2ddd292593d412ec760b57028 Initial file load | ||
| 69d88ec081a75a52b8b7661da0251325906de3b2 Initial commit | 69d88ec081a75a52b8b7661da0251325906de3b2 Initial commit | ||
| - | |||
| - | ====submodules==== | ||
| - | |||
| In the listings above jslib shows as an empty folder in the worktree,\\ | In the listings above jslib shows as an empty folder in the worktree,\\ | ||
| and as a commit in the .git database.\\ | and as a commit in the .git database.\\ | ||
| That is the commit that was originally pulled into this super-project. | That is the commit that was originally pulled into this super-project. | ||
| - | |||
| - | |||
| - | git submodule update | ||
| - | This gets the url from .git/config [jslib] section. | ||
| - | And it gets the commit | ||
| - | When we do a git | ||
| - | |||
| - | |||
| - | ====Move a Superproject to a New Server==== | ||
| - | |||
| - | A superproject contains submodules.\\ | ||
| - | Each submodule is identified by name, url, and commit-ish.\\ | ||
| - | The name and url are specified in the .gitmodules file.\\ | ||
| - | The commit-ish is retained in the database, as shown by '' | ||
| - | |||
| - | |||
| - | **Step 1.** manually edit the .gitmodules file.\\ | ||
| - | Here we specify the new server url. | ||
| - | |||
| - | **Step 2.** '' | ||
| - | This copies the changes in .gitmodules into the .git/config file. | ||
| - | |||
| - | **Step 3.** '' | ||
| - | This pulls a version of submodule jslib into the jslib folder, \\ | ||
| - | using the url found in .git/config and the jslib commit-ish found in the layer/.git database. | ||
| - | This version may not be the latest, and therefore we continue with step 4. | ||
| - | |||
| - | **Step 4.** '' | ||
| - | This pulls the latest commit from the jslib/.git. | ||
| - | |||
| - | **Step 5.** Add, commit and push the layout superproject. | ||
| - | $ git status | ||
| - | modified files | ||
| - | .gitmodules | ||
| - | jslib (new commits) | ||
| - | |||
| - | git add . | ||
| - | git commit -m 'Pull latest submodules' | ||
| - | git push origin master | ||
git.1725096224.txt.gz · Last modified: 2024/08/31 05:23 by jhagstrand