Size: 904
Comment:
|
← Revision 12 as of 2025-01-29 15:37:43 ⇥
Size: 3084
Comment: Patches
|
Deletions are marked like this. | Additions are marked like this. |
Line 3: | Line 3: |
This document covers the setup of a git remote server. For information on using `git` as an end-user, consider instead: | '''Git''' is a version control system designed to be used in a distributed ecosystem and primarily interfaced in a terminal (i.e. `git(1)`). |
Line 5: | Line 5: |
* [[GitBranches]] | Compare to [[Cvs|CVS]]. |
Line 12: | Line 12: |
== Web Interfaces == | == Installation == |
Line 14: | Line 14: |
=== CGit === | All [[Linux]] distributions offer a `git` package. Most [[BSD]] distributions do as well. |
Line 16: | Line 16: |
[[CGitSetup|CGit]] is a very lightweight and resource-efficient solution for viewing git repositories in the web. Fundamentally it is ''only'' a tool for viewing a git repository: | On [[Windows]], see the [[https://gitforwindows.org/|Git for Windows]] project. |
Line 18: | Line 18: |
* You must maintain a git repository local to the '''CGit''' instance * There is no integrated bug or issue tracker * Features generally considered mandatory-like authentication, rendering of markdown `README` files, and syntax highlighting-are dependent on filter plugins |
---- |
Line 22: | Line 20: |
Given the lightweight nature and minimal feature set, '''CGit''' is ideal for entirely public projects that handle bug tracking independently of source code hosting, or for hosting private code on an intranet. | == Usage == To begin tracking a directory, run `git init`. This creates a `.git` folder to maintain the internal state of the version control system. Use `git status` to show the current state in a human-readable format. === Branches === For more information about using branches, see [[Git/Branches|here]]. === Submodules === To clone a repository that uses submodules, try: {{{ git clone --recurse-submodules git@github.com:example/example.git }}} Alternatively, submodules can be pulled in a separate step. {{{ git clone git@github.com:example/example.git cd example git submodule update --init --recursive }}} To add a submodule, try: {{{ git submodule add git@github.com:example/subexample }}} To delete a submodule, try: {{{ git submodule deinit subexample }}} === Patches === To create a patch, try: {{{ git format-patch -1 HEAD }}} Generally, the `HEAD` can be omitted. This creates a patch file that can be applied like: {{{ git apply 0001-Commit-Message-Here.patch }}} To create a patchset of the last 3 commits, try: {{{ git format-patch -2 }}} This will create a series of patches that are named sequentially like `0001-Commit-1.patch`, `0002-Commit-2.patch`, and so on. Note that applying a patch with `git apply` simply changes local files. It does ''not'' create a local commit. Compare to `git am`, which is meant for applying patches as commits, including metadata embedded into the patchset (i.e., creator, date, etc.). To create a squashed patch, try: {{{ # Assumes that local work is in a development branch # Create a temporary branch to house a squashed commit from the development branch git checkout -b temporary-branch git merge --squash development-branch git commit -a -m "Squashed Commit Message" # Create a patch against the main branch (usually either `master` or `main`) git format-patch main # Finally return to main branch delete the temporary branch git checkout main git branch -d temporary-branch }}} ---- == Troubleshooting == === Fatal error when cloning a remote repository === If git fails to clone a remote repository, possibly with one of the following error messages: {{{ fatal: fetch-pack: invalid index-pack output ... fatal: early EOF fatal: index-pack failed }}} Then try a '''shallow clone''' first: {{{ git clone --depth 1 https://example.com/repo.git git fetch --unshallow git pull --all }}} ---- == See also == [[https://man.archlinux.org/man/git.1|git(1)]] [[Git/GitShell|git-shell]] [[CGit|CGit]] ---- CategoryRicottone |
Git
Git is a version control system designed to be used in a distributed ecosystem and primarily interfaced in a terminal (i.e. git(1)).
Compare to CVS.
Contents
Installation
All Linux distributions offer a git package. Most BSD distributions do as well.
On Windows, see the Git for Windows project.
Usage
To begin tracking a directory, run git init. This creates a .git folder to maintain the internal state of the version control system.
Use git status to show the current state in a human-readable format.
Branches
For more information about using branches, see here.
Submodules
To clone a repository that uses submodules, try:
git clone --recurse-submodules git@github.com:example/example.git
Alternatively, submodules can be pulled in a separate step.
git clone git@github.com:example/example.git cd example git submodule update --init --recursive
To add a submodule, try:
git submodule add git@github.com:example/subexample
To delete a submodule, try:
git submodule deinit subexample
Patches
To create a patch, try:
git format-patch -1 HEAD
Generally, the HEAD can be omitted.
This creates a patch file that can be applied like:
git apply 0001-Commit-Message-Here.patch
To create a patchset of the last 3 commits, try:
git format-patch -2
This will create a series of patches that are named sequentially like 0001-Commit-1.patch, 0002-Commit-2.patch, and so on.
Note that applying a patch with git apply simply changes local files. It does not create a local commit. Compare to git am, which is meant for applying patches as commits, including metadata embedded into the patchset (i.e., creator, date, etc.).
To create a squashed patch, try:
# Assumes that local work is in a development branch # Create a temporary branch to house a squashed commit from the development branch git checkout -b temporary-branch git merge --squash development-branch git commit -a -m "Squashed Commit Message" # Create a patch against the main branch (usually either `master` or `main`) git format-patch main # Finally return to main branch delete the temporary branch git checkout main git branch -d temporary-branch
Troubleshooting
Fatal error when cloning a remote repository
If git fails to clone a remote repository, possibly with one of the following error messages:
fatal: fetch-pack: invalid index-pack output ... fatal: early EOF fatal: index-pack failed
Then try a shallow clone first:
git clone --depth 1 https://example.com/repo.git git fetch --unshallow git pull --all