Tag: Source edit |
|||
(203 intermediate revisions by the same user not shown) | |||
Line 3: | Line 3: | ||
<div class='by-3rdstage'> |
<div class='by-3rdstage'> |
||
− | == |
+ | ==Fundamentals== |
* [http://git-scm.com/documentation Git Documentation] |
* [http://git-scm.com/documentation Git Documentation] |
||
+ | |||
− | {| class="wikitable" style="margin-left:40px" |
||
+ | * [http://git-scm.com/docs Git Reference] |
||
− | ! category !! command !! description !! remark |
||
+ | ** [https://git-scm.com/docs/git-config#_variables Git configuration variables] |
||
+ | ** [https://git-scm.com/docs/revisions Revisions] |
||
+ | ** [https://git-scm.com/docs/gitignore#_pattern_format <code>gitignore</code> Pattern Format] |
||
+ | * [https://git-scm.com/book/en/v2 ''Pro Git''] |
||
+ | ** [https://git-scm.com/book/en/v2/Git-Internals-Git-References '''Git References'''] |
||
+ | ** [https://git-scm.com/book/en/v2/Git-Branching-Branches-in-a-Nutshell Git Branching] |
||
+ | ** [https://git-scm.com/book/en/v2/Git-Branching-Remote-Branches '''Remote Branches'''] |
||
+ | * [https://help.github.com/categories/54/articles GitHub Bootcamp] |
||
+ | ** As of Nov. 1st 2012, one important thing is missing. That is sharing the project in Eclipse, after cloning the fork in the server. Maybe it could be a defect of Eclipse, not a miss of the article. |
||
+ | * [http://ndpsoftware.com/git-cheatsheet.html Git Cheatsheet] |
||
+ | ** [http://ndpsoftware.com/git-cheatsheet.html#loc=workspace; Workspace] |
||
+ | ** [http://ndpsoftware.com/git-cheatsheet.html#loc=local_repo; Local Repository] |
||
+ | ** [http://ndpsoftware.com/git-cheatsheet.html#loc=remote_repo; Upstream Repository] |
||
+ | * [https://www.atlassian.com/git/tutorials Git Tutorials by Bitbucket] |
||
+ | * [https://www.atlassian.com/git/workflows Git Workflows by Bitbucket] |
||
+ | * [http://wiki.eclipse.org/EGit EGit User Guide] |
||
+ | ** [http://wiki.eclipse.org/EGit/User_Guide#Git_References Git References(Refs)] |
||
+ | ** [http://wiki.eclipse.org/EGit/User_Guide#Remotes Remotes] |
||
+ | |||
+ | ===Glossary=== |
||
+ | |||
+ | * [http://git-scm.com/docs/gitglossary Git Glossary] |
||
+ | |||
+ | {| class='wikitable' |
||
+ | ! Term !! Description !! Examples !! Remarks |
||
|- |
|- |
||
+ | | [https://git-scm.com/docs/gitglossary#Documentation/gitglossary.txt-aiddefcommitacommit <code>commit</code>] (noun) |
||
− | | Setup || [https://git-scm.com/docs/git-config <code>git config</code>] || Get and set repository or global options || <code>git config --get core.autocrlf</code><br/><code>git config core.autocrlf false</code> |
||
+ | | A single point in the Git history || || <tt>revision</tt>, <tt>version</tt> |
||
|- |
|- |
||
− | + | | [https://git-scm.com/docs/gitglossary#Documentation/gitglossary.txt-aiddefcommitobjectacommitobject <code>commit object</code>] |
|
+ | | An object which contains the information about a particular revision, such as parents, committer, author, date and the tree object which corresponds to the top directory of the stored revision. || || |
||
|- |
|- |
||
+ | | [http://git-scm.com/docs/gitglossary#Documentation/gitglossary.txt-aiddefcommit-ishacommit-ishalsocommittish <code>commit-ish</code>] |
||
− | | || [https://git-scm.com/docs/git-init <tt>git init</tt>] || Create an empty Git repository or reinitialize an existing one || |
||
+ | | A commit object or an object that can be recursively dereferenced to a commit object || || commit object, tag object |
||
|- |
|- |
||
− | + | | [http://git-scm.com/docs/gitglossary#Documentation/gitglossary.txt-aiddeftreeatree <code>tree</code>] |
|
+ | | Either a working tree, or a tree object together with the dependent blob and tree objects (i.e. a stored representation of a working tree) || || |
||
|- |
|- |
||
− | + | | [http://git-scm.com/docs/gitglossary#Documentation/gitglossary.txt-aiddeftreeobjectatreeobject <code>tree object</code>] |
|
+ | | An object containing a list of file names and modes along with refs to the associated blob and/or tree objects || || |
||
|- |
|- |
||
+ | | [http://git-scm.com/docs/gitglossary#Documentation/gitglossary.txt-aiddeftree-ishatree-ishalsotreeish <code>tree-ish</code>] |
||
− | | || [https://git-scm.com/docs/git-diff <code>git diff</code>] || Show changes between commits, commit and working tree, etc || |
||
+ | | A commit-ish, a tree object or a tag object || || |
||
+ | |- |
||
+ | | [http://git-scm.com/docs/gitglossary#Documentation/gitglossary.txt-aiddefpathspecapathspec <code>pathspec</code>] |
||
+ | | Pattern used to limit paths in Git commands || <tt>documentation/*.jpg</tt> || |
||
+ | |- |
||
+ | | [http://git-scm.com/docs/gitglossary#Documentation/gitglossary.txt-aiddefrefaref <code>ref</code>] |
||
+ | | A name that begins with <code>refs/</code> (e.g. <code>refs/heads/master</code>) that points to an object name or another <tt>ref</tt> (the latter is called a symbolic ref) || || |
||
+ | |- |
||
+ | | [http://git-scm.com/docs/gitglossary#Documentation/gitglossary.txt-aiddefrefspecarefspec <code>refspec</code>] |
||
+ | | Used by <code>fetch</code> and <code>push</code> to describe the mapping between remote ref and local ref || || [http://git-scm.com/docs/git-push#Documentation/git-push.txt-ltrefspecgt82308203 <code>push</code> <tt>refspec</tt>] |
||
+ | |- |
||
+ | | [https://git-scm.com/docs/gitglossary#Documentation/gitglossary.txt-aiddefHEADaHEAD <code>HEAD</code>] |
||
+ | | The current branch. In more detail: Your working tree is normally derived from the state of the tree referred to by <code>HEAD</code>. |
||
+ | | || <code>detached HEAD</code>, <code>HEAD ≠ head</code> |
||
+ | |- |
||
+ | | [https://git-scm.com/docs/gitglossary#Documentation/gitglossary.txt-aiddefdetachedHEADadetachedHEAD <code>detached HEAD</code>] |
||
+ | | Git also allows you to check out an arbitrary commit that isn’t necessarily the tip of any particular branch. The HEAD in such a state is called "detached". || || |
||
+ | |- |
||
+ | | [http://git-scm.com/docs/gitglossary#Documentation/gitglossary.txt-aiddefupstreambranchaupstreambranch <code>upstream branch</code>] |
||
+ | | The default branch that is merged into the branch in question (or the branch in question is rebased onto) || || |
||
+ | * <code>branch.''name''.remote</code> |
||
+ | * <code>branch.''name''.merge</code> |
||
+ | * upstream branch of ''br'' is ''origin/br′'' = ''br'' is tracking ''origin/br′'' |
||
+ | |} |
||
+ | |||
+ | * [https://itecnote.com/tecnote/git-what-are-commit-ish-and-tree-ish-in-git/ What are <code>commit-ish</code> and <code>tree-ish</code> in Git] |
||
+ | |||
+ | ===Revision=== |
||
+ | |||
+ | * [https://git-scm.com/docs/revisions#_specifying_revisions Specifying Revisions] |
||
+ | |||
+ | {| class='wikitable' |
||
+ | ! Type !! Format !! Description !! Examples |
||
+ | |- |
||
+ | | <code>sha1</code> || 40-byte hexadecimal string |
||
+ | | The full SHA-1 object name, or a leading substring that is unique within the repository |
||
+ | | <code>dae86e1950b1277e545cee180551750029cfe735</code>, <code>dae86e</code> |
||
+ | |- |
||
+ | | <code>refname</code> || || A symbolic ref name || <code>master</code>, <code>heads/master</code>, <code>refs/heads/master</code>, <code>tags/master</code> |
||
+ | |- |
||
+ | | <code><nowiki><rev>^[<n>]</nowiki></code> || || the <tt><n></tt>th parent || <code>HEAD^</code>, <code>v1.5.1^0</code>, <code>HEAD^^^</code>, <code>HEAD^^3^2</code> |
||
+ | |- |
||
+ | | <code><nowiki><rev>~[<n>]</nowiki></code> || |
||
+ | | the commit object that is the <tt><n></tt>th generation ancestor of the named commit object || <code>HEAD~</code>, <code>HEAD~4</code> <code>master~3</code> |
||
+ | |- |
||
+ | | <code><nowiki><rev>:<path></nowiki></code> || |
||
+ | | the blob or tree at the given path in the tree-ish object named by the part before the colon. || <code>HEAD:README</code>, <code>master:./README</code> |
||
+ | |} |
||
+ | |||
+ | * An illustration, by Jon Loeliger |
||
+ | <syntaxhighlight lang='text' enclose='div'> |
||
+ | G H I J |
||
+ | \ / \ / |
||
+ | D E F |
||
+ | \ | / \ |
||
+ | \ | / | |
||
+ | \|/ | |
||
+ | B C |
||
+ | \ / |
||
+ | \ / |
||
+ | A |
||
+ | |||
+ | |||
+ | A = = A^0 |
||
+ | B = A^ = A^1 = A~1 |
||
+ | C = = A^2 |
||
+ | D = A^^ = A^1^1 = A~2 |
||
+ | E = B^2 = A^^2 |
||
+ | F = B^3 = A^^3 |
||
+ | G = A^^^ = A^1^1^1 = A~3 |
||
+ | H = D^2 = B^^2 = A^^^2 = A~2^2 |
||
+ | I = F^ = B^3^ = A^^3^ |
||
+ | J = F^2 = B^3^2 = A^^3^2 |
||
+ | </syntaxhighlight> |
||
+ | |||
+ | ===Commands=== |
||
+ | |||
+ | {| class="wikitable" |
||
+ | ! Category !! Command !! Description !! Remark |
||
+ | |- |
||
+ | | Setup || [https://git-scm.com/docs/git-config <code>git config <nowiki>[</nowiki>--get<nowiki>]</nowiki></code>] |
||
+ | | Get and set repository(local) options |
||
+ | | <code>git config --get core.autocrlf</code><br/><code>git config core.autocrlf false</code> |
||
+ | |- |
||
+ | | || [https://git-scm.com/docs/git-config#Documentation/git-config.txt---global <code>git config --global <nowiki>[</nowiki>--get<nowiki>]</nowiki></code>] |
||
+ | | Get and set global options |
||
+ | | <code>git config --global --get committer.name</code><br/><code>git config --global init.defaultBranch main</code> |
||
+ | |- |
||
+ | | || [https://git-scm.com/docs/git-config#Documentation/git-config.txt---list <code>git config --list --show-origin</code>] |
||
+ | | List all variables set in config file, along with their values. || |
||
+ | |- |
||
+ | | || [https://git-scm.com/docs/git-help#Documentation/git-help.txt---all <code>git help --all</code>] |
||
+ | | Prints all the available commands on the standard output || |
||
+ | |- |
||
+ | | || [https://git-scm.com/docs/git-help#Documentation/git-help.txt--m <code>git help -m ''command''</code>] |
||
+ | | Display manual page for the command in the man format || |
||
+ | |- |
||
+ | | Creating || [http://git-scm.com/docs/git-clone <code>git clone</code>] |
||
+ | | Clone a repository into a new directory || |
||
+ | |- |
||
+ | | || [https://git-scm.com/docs/git-init <code>git init</code>] |
||
+ | | Create an empty Git repository or reinitialize an existing one || |
||
+ | |- |
||
+ | | Snapshotting || [http://git-scm.com/docs/git-add <code>git add</code>] || || |
||
+ | |- |
||
+ | | || [http://git-scm.com/docs/git-status <code>git status</code>] |
||
+ | | Show the working tree status || |
||
+ | |- |
||
+ | | || [https://git-scm.com/docs/git-diff#Documentation/git-diff.txt-emgitdiffemltoptionsgt--ltpathgt82308203 <code>git diff <nowiki>[--]</nowiki> ''path''</code>] |
||
+ | | Show changes you made relative to the index (staging area for the next commit) || working tree (excluding untracked files) vs index |
||
+ | |- |
||
+ | | || [https://git-scm.com/docs/git-diff/2.6.7#Documentation/git-diff.txt-emgitdiffem--optionsltcommitgt--ltpathgt82308203 <code>git diff ''commit'' <nowiki>[--]</nowiki> ''path''] |
||
+ | | Show the changes you have in your working tree relative to the named ''commit'' || working tree (excluding untracked files) vs commit |
||
+ | |- |
||
+ | | || [https://git-scm.com/docs/git-diff#Documentation/git-diff.txt-emgitdiffemltoptionsgt--cached--merge-baseltcommitgt--ltpathgt82308203 <code>git diff --staged ''commit'' <nowiki>[--]</nowiki> ''path''] |
||
+ | | the changes you staged for the next commit relative to the named ''commit'' (default to <code>HEAD</code>). || index vs commit |
||
+ | |- |
||
+ | | || [https://git-scm.com/docs/git-diff#Documentation/git-diff.txt-emgitdiffemltoptionsgtltblobgtltblobgt <code>git diff ''blob1'' ''blob2''</code>] |
||
+ | | Show differences between the raw contents of two blob objects || <code>git diff HEAD:docs/GUIDELINES.md HEAD~1:docs/GUIDELINES.md</code> |
||
+ | |- |
||
+ | | || [https://git-scm.com/docs/git-diff#Documentation/git-diff.txt-emgitdiffemltoptionsgtltcommitgtltcommitgt--ltpathgt82308203 <code>git diff ''commit1'' ''commit2'' <nowiki>[--]</nowiki> ''path''</code>] |
||
+ | | Show changes between two arbitrary commits || <code>git diff HEAD HEAD^ docs/GUIDELINES.md</code> |
||
+ | |- |
||
+ | | || [https://git-scm.com/docs/git-diff#Documentation/git-diff.txt---name-only <code>git diff --name-only ''commit1'' ''commit2''</code>] |
||
+ | | Show only names of changed files between two arbitrary commits || <code>git diff --name-only v1.2.1 HEAD</code> |
||
+ | |- |
||
+ | | || [https://git-scm.com/docs/git-diff#Documentation/git-diff.txt---name-status <code>git diff --name-status ''commit1'' ''commit2''</code>] |
||
+ | | Show only names and status of changed files between two arbitrary commits || |
||
+ | |- |
||
+ | | || [https://git-scm.com/docs/git-diff#Documentation/git-diff.txt---summary <code>git diff --summary ''commit1'' ''commit2''</code>] |
||
+ | | Output a condensed summary of extended header information such as creations, renames and mode changes. || |
||
+ | |- |
||
+ | | || [https://git-scm.com/docs/git-diff#Documentation/git-diff.txt---statltwidthgtltname-widthgtltcountgt <code>git diff --stat ''commit1'' ''commit2''</code>] |
||
+ | | || |
||
|- |
|- |
||
| || [http://git-scm.com/docs/git-commit <code>git commit</code>] || || |
| || [http://git-scm.com/docs/git-commit <code>git commit</code>] || || |
||
|- |
|- |
||
− | | | |
+ | | || [https://git-scm.com/docs/git-reset <code>git reset</code>] |
+ | | Reset current HEAD to the specified state || |
||
|- |
|- |
||
− | | |
+ | | || [https://git-scm.com/docs/git-reset#git-reset---hard <code>git reset --hard</code>] |
+ | | Resets the index and working tree. Any changes to tracked files in the working tree since commit are discarded. || |
||
|- |
|- |
||
− | | || [ |
+ | | || [https://git-scm.com/docs/git-reset#Documentation/git-reset.txt-emgitresetemltmodegtltcommitgt <code>git reset --hard ''commit''</code>] |
+ | | Resets the current branch head to ''commit'' |
||
+ | | [https://git-scm.com/docs/git-reset#Documentation/git-reset.txt-Undocommitspermanently Undo commits permanently] |
||
|- |
|- |
||
− | | || [https://git-scm.com/docs/git- |
+ | | || [https://git-scm.com/docs/git-reset#Documentation/git-reset.txt-emgitresetem-qlttree-ishgt--ltpathspecgt82308203 <code>git reset ''commit'' <nowiki>[--]</nowiki> ''path''</code>] |
+ | | Reset the index entries for all that match the ''path'' to their state at ''commit'' || <code>git reset HEAD CONTRIBUTING.md</code> |
||
|- |
|- |
||
− | | || [https://git-scm.com/docs/git- |
+ | | || [https://git-scm.com/docs/git-restore <code>git restore</code>] |
+ | | Restore working tree files or the content in the index || |
||
+ | |- |
||
+ | | || [https://git-scm.com/docs/git-restore#Documentation/git-restore.txt---worktree <code>git resotre <nowiki>[--worktree]</nowiki> ''path''</code>] |
||
+ | | Restore working tree files that match the ''path'' from the index || |
||
+ | |- |
||
+ | | || [https://git-scm.com/docs/git-restore#Documentation/git-restore.txt---staged <code>git reset --staged ''path''</code>] |
||
+ | | Restore the contents of the index that match the ''path'' from <code>HEAD</code> || |
||
+ | |- |
||
+ | | || [https://git-scm.com/docs/git-rm <code>git rm</code>] |
||
+ | | Remove files from the working tree and from the index || |
||
+ | |- |
||
+ | | || [https://git-scm.com/docs/git-rm#Documentation/git-rm.txt---cached <code>git rm -rf --cached</code>] |
||
+ | | Only remove from the index || Working tree files, whether modified or not, will be left alone |
||
+ | |- |
||
+ | | Branching || [http://git-scm.com/docs/git-branch <code>git branch</code>] |
||
+ | | List, create, or delete branches || |
||
+ | |- |
||
+ | | || [https://git-scm.com/docs/git-branch#Documentation/git-branch.txt---list <code>git branch --list</code>] |
||
+ | | List branches. || <code>-l</code> |
||
+ | |- |
||
+ | | || [https://git-scm.com/docs/git-branch#Documentation/git-branch.txt--a '''<code>git branch --all -vvvv</code>'''] |
||
+ | | List both remote-tracking branches and local branches. || <code>-avvvv</code> |
||
+ | |- |
||
+ | | || [https://git-scm.com/docs/git-branch#Documentation/git-branch.txt--m <code>git branch --move ''oldbranch'' ''newbranch''</code>] |
||
+ | | Move/rename a branch and the corresponding reflog. || <code>-m</code> |
||
+ | |- |
||
+ | | || [https://git-scm.com/docs/git-branch#Documentation/git-branch.txt--d <code>git branch --delete <nowiki>[</nowiki>--force<nowiki>]</nowiki> ''branch''</code>] |
||
+ | | Delete a branch. || <code>-d</code>, <code>-D</code> |
||
+ | |- |
||
+ | | || [http://git-scm.com/docs/git-checkout <code>git checkout ''branch''</code>] |
||
+ | | To prepare for working on ''<tt>branch</tt>'', switch to it by updating the index and the files in the working tree, and by pointing <tt>HEAD</tt> at the ''<tt>branch</tt>'' || |
||
+ | |- |
||
+ | | || [https://git-scm.com/docs/git-checkout#Documentation/git-checkout.txt-emgitcheckoutem-f--ours--theirs-m--conflictltstylegtlttree-ishgt--ltpathspecgt82308203 <code>git checkout ''commit'' <nowiki>[</nowiki> -- <nowiki>]</nowiki> ''pathspec''</code>] |
||
+ | | Overwrite both the index and the working tree that match the ''<tt>pathspec</tt>'' with the contents at the ''<tt>commit</tt>''. |
||
+ | | [https://stackoverflow.com/questions/2364147/how-to-get-just-one-file-from-another-branch/2364223 just one file from another branch] |
||
+ | |- |
||
+ | | || style='white-space:nowrap' | [https://git-scm.com/docs/git-checkout#Documentation/git-checkout.txt-emgitcheckoutemltbranchgt <code>git checkout -b ''new-branch'' <nowiki>[</nowiki> ''start-point'' <nowiki>]</nowiki> --track ''remote''/''branch''</code>] |
||
+ | | Create and check out a new branch tracking the specified remote branch from <code>HEAD</code> or the specified ''<tt>start-point</tt>'' if any || <code>git checkout -b simpler HEAD~3</code> |
||
+ | |- |
||
+ | | || [https://git-scm.com/docs/git-checkout#Documentation/git-checkout.txt--t <code>git checkout --track ''remote''/''branch''</code>] |
||
+ | | Create and check out a new branch which is tracking and named from the specified remote branch || <code>git checkout -t ''remote''/''branch''</code> |
||
+ | |- |
||
+ | | || [https://git-scm.com/docs/git-push#Documentation/git-push.txt-ltrefspecgt82308203 <code>git push --set-upstream ''repository'' ''src-branch'':''dst-branch''</code>] |
||
+ | | Push ''<tt>src-branch</tt>'' into ''<tt>dst-branch</tt>'' in ''<tt>repository</tt>'' creating a new branch if ''<tt>dst-branch</tt>'' dose not exist yet and then set the ''<tt>src-branch</tt>'' to track the ''<tt>dst-branch</tt>'' || |
||
+ | |- |
||
+ | | || [http://git-scm.com/docs/git-branch#Documentation/git-branch.txt--ultupstreamgt <code>git branch --set-upstream-to=''remote''/''branch′'' ''branch''</code>] |
||
+ | | Set up the branch (specified by <tt>''branch''</tt>) tracking information so the upstream specified by <tt>''remote''/branch′''</tt> is considered it's upstream branch. || <code>git branch --set-upstream-to=origin/bar bar</code><br/><code>git branch -u origin/bar bar</code> |
||
|- |
|- |
||
− | | |
+ | | || [http://git-scm.com/docs/git-branch#Documentation/git-branch.txt--ultupstreamgt <code>git branch --set-upstream-to=''upstream''</code>] |
+ | | Set up current branch tracking information so the upstream specified by ''upstream'' is considered it's upstream branch. || <code>git branch --set-upstream-to=origin/foo</code><br/><code>git branch -u origin/foo</code> |
||
|- |
|- |
||
− | | || [http://git-scm.com/docs/git- |
+ | | || [http://git-scm.com/docs/git-checkout#Documentation/git-checkout.txt-emgitcheckoutem-f--ours--theirs-m--conflictltstylegtlttree-ishgt--ltpathspecgt82308203 <code>git checkout ''branch'' <nowiki>[--]</nowiki> ''pathspec''] |
+ | | Overwrite the contents of the files that match the ''<tt>pathspec</tt>'' in both the index and the working tree with the contents at the specified ''<tt>branch</tt>'' || |
||
|- |
|- |
||
− | | || [https://git-scm.com/docs/git- |
+ | | || [https://git-scm.com/docs/git-checkout#Documentation/git-checkout.txt-emgitcheckoutem-p--patchlttree-ishgt--ltpathspecgt82308203 <code>git checkout --patch ''branch'' <nowiki>[--]</nowiki> ''pathspec''] |
+ | | Overwrite the contents of the files that match the ''<tt>pathspec</tt>'' with the interactive interface to show the "diff" output and choose which hunks to use in the result. || <code>--patch</code>, <code>-p</code> |
||
|- |
|- |
||
− | | |
+ | | || [http://git-scm.com/docs/git-merge#Documentation/git-merge.txt---ff <code>git merge <nowiki>[--ff | --no-ff | --ff-only]</nowiki> ''commit''</code>] |
+ | | Join two or more development histories together || |
||
|- |
|- |
||
− | | |
+ | | || [https://git-scm.com/docs/git-merge#Documentation/git-merge.txt---abort <code>git merge --abort</code>] |
+ | | Abort the current conflict resolution process, and try to reconstruct the pre-merge state. || |
||
|- |
|- |
||
− | | || [https://git-scm.com/docs/git- |
+ | | || [https://git-scm.com/docs/git-log <code>git log <nowiki>[</nowiki>''branch''<nowiki>]</nowiki> -''n''</code>] |
+ | | Show commit logs || <code>git log master -3</code> |
||
|- |
|- |
||
− | | |
+ | | || [https://git-scm.com/docs/git-log#Documentation/git-log.txt---graph <code>git log <nowiki>[</nowiki>-''n''<nowiki>]</nowiki> --graph</code> <nowiki>[</nowiki>--all<nowiki>]</nowiki>] |
+ | | Draw a text-based graphical representation of the commit history on the left hand side of the output. || <code>git log -3 --graph</code> |
||
|- |
|- |
||
− | | || [https://git-scm.com/docs/git- |
+ | | || [https://git-scm.com/docs/git-tag <code>git tag</code>] |
+ | | Create, list, delete or verify a tag object signed with GPG || |
||
|- |
|- |
||
− | | |
+ | | || [https://git-scm.com/docs/git-tag#Documentation/git-tag.txt--l <code>git tag --list -n2</code>] |
+ | | List tags || <code>git tag -l</code> |
||
|- |
|- |
||
− | | |
+ | | || [https://git-scm.com/docs/git-tag#Documentation/git-tag.txt---formatltformatgt <code>git tag --list --sort=-taggerdate --format='%(refname:short), %(*objectname), %(contents:subject)'</code>] |
+ | | List tags with commit hash and annotation ordered, last tag first || [https://github.com/git/git/blob/v2.17.0/ref-filter.c#L328 format field names] |
||
+ | |- |
||
+ | | || [https://git-scm.com/docs/git-tag#Documentation/git-tag.txt--a <code>git tag --annotate ''tagname'' -m "..."</code>] |
||
+ | | Make(create) an unsigned, annotated tag object || <code>git tag -a</code> |
||
+ | |- |
||
+ | | || [https://git-scm.com/docs/git-tag#Documentation/git-tag.txt--d <code>git tag --delete ''tagname''</code>] |
||
+ | | Delete an existing tag with the given name. || <code>git tag -d</code> |
||
+ | |- |
||
+ | | Sharing || [https://git-scm.com/docs/git-fetch <code>git fetch</code>] |
||
+ | | Fetch branches and/or tags (collectively, "refs") from one or more other repositories, along with the objects necessary to complete their histories. |
||
+ | | <tt>git remote add ''staging''; git fetch ''staging''</tt> |
||
+ | |- |
||
+ | | || [https://git-scm.com/docs/git-fetch <code>git fetch <nowiki>[</nowiki>''remote'' ''remote-branch''<nowiki>]</nowiki></code>] || || |
||
+ | |- |
||
+ | | || [http://git-scm.com/docs/git-pull <code>git pull <nowiki>[</nowiki>''remote'' ''remote-branch''<nowiki>]</nowiki></code>] |
||
+ | | Incorporates changes from a remote repository into '''the current branch''' || current branch only |
||
+ | |- |
||
+ | | || [http://git-scm.com/docs/git-push <code>git push <nowiki>[</nowiki>''remote'' <nowiki>[</nowiki>''src-branch''<nowiki>[</nowiki>:''dst-branch''<nowiki>]</nowiki>...<nowiki>]]</nowiki></code>] |
||
+ | | Push specified branches to the specified remote repository. || <code>branch.*.remote</code>, <code>origin</code> |
||
+ | |- |
||
+ | | || [http://git-scm.com/docs/git-push <code>git push ''remote'' ''tag-name''</code>] |
||
+ | | Push a tag to the specified remote repository || <code>git push origin v1.3.0-alpha</code> |
||
+ | |- |
||
+ | | || [https://git-scm.com/docs/git-push#Documentation/git-push.txt---all <code>git push --all <nowiki>[</nowiki>''remote''<nowiki>]</nowiki></code>] |
||
+ | | Push all branches (i.e. refs under <code>refs/heads/</code>) into default remote, <code>origin</code>, or specified remote || |
||
+ | |- |
||
+ | | || [https://git-scm.com/docs/git-push#Documentation/git-push.txt---tags <code>git push --tags <nowiki>[</nowiki>''remote''<nowiki>]</nowiki></code>] |
||
+ | | All refs under <code>refs/tags</code> are pushed || |
||
+ | |- |
||
+ | | || [https://git-scm.com/docs/git-push#Documentation/git-push.txt---tags <code>git push --follow-tags</code>] |
||
+ | | Push all the refs that would be pushed without this option, and also push annotated tags in <code>refs/tags</code> that are missing from the remote but are pointing at commit-ish that are reachable from the refs being pushed. || |
||
+ | |- |
||
+ | | || [https://git-scm.com/docs/git-push#Documentation/git-push.txt---delete <code>git push --delete ''tagname''</code>] |
||
+ | | Delete a remote tag with the given name. || <code>git push -d</code> |
||
+ | |- |
||
+ | | || [https://git-scm.com/docs/git-push#Documentation/git-push.txt---set-upstream <code>git push --set-upstream</code>] |
||
+ | | For every branch that is up to date or successfully pushed, add upstream (tracking) reference, used by argument-less <code>git-pull</code> and other commands. || |
||
+ | |- |
||
+ | | || [https://git-scm.com/docs/git-remote <code>git remote -v</code>] |
||
+ | | List tracked repositories || |
||
+ | |- |
||
+ | | || [https://git-scm.com/docs/git-remote#Documentation/git-remote.txt-emaddem <code>git remote add ''name'' ''url''</code>] |
||
+ | | Add a remote || <code>git remote add upstream https://....git</code> |
||
+ | |- |
||
+ | | || [https://git-scm.com/docs/git-remote#Documentation/git-remote.txt-emset-urlem <code>git remote set-url ''name'' ''url''</code>] |
||
+ | | Changes URLs for the remote || |
||
+ | |- |
||
+ | | || [https://git-scm.com/docs/git-remote#Documentation/git-remote.txt-emrenameem <code>git remote rename ''old'' ''new''</code>] |
||
+ | | Rename a remote || |
||
+ | |- |
||
+ | | || [https://git-scm.com/docs/git-remote#Documentation/git-remote.txt-emrmem <code>git remote remove</code>] |
||
+ | | Remove a remote || <code>git remote rm</code> |
||
+ | |- |
||
+ | | || [https://git-scm.com/docs/git-remote#Documentation/git-remote.txt-emshowem <code>git remote -v show ''name''</code>] |
||
+ | | Gives some information about a remote || <code>git remote -v show origin</code> |
||
+ | |- |
||
+ | | || [https://git-scm.com/docs/git-ls-remote <code>git ls-remote</code>] |
||
+ | | List references in a remote repository || <code>git ls-remote origin</code> |
||
+ | |- |
||
+ | | Inspection || [https://git-scm.com/docs/git-show <code>git show ''tag''</code>] |
||
+ | | Shows the tag message and the referenced objects. || <code>git show v1.0</code> |
||
+ | |- |
||
+ | | || [https://git-scm.com/docs/git-show <code>git show ''rev'':''path''</code>] |
||
+ | | Shows the contents of the file specified by ''<code>path</code>'' at ''<code>rev</code>'' || <code>git show HEAD~10:./README.md</code> |
||
+ | |- |
||
+ | | Stashing || [http://git-scm.com/docs/git-stash#Documentation/git-stash.txt-listltlog-optionsgt <code>git stash list</code>] |
||
+ | | List the stash entries that you currently have. || <code>stash@{0}</code>, <code>stash@{1}</code> |
||
+ | |- |
||
+ | | || [http://git-scm.com/docs/git-stash#Documentation/git-stash.txt-show-u--include-untracked--only-untrackedltdiff-optionsgtltstashgt <code>git stash show ''stash''</code>] |
||
+ | | Show the changes recorded in the stash entry as a diff between the stashed contents and the commit back when the stash entry was first created || |
||
+ | |- |
||
+ | | || [http://git-scm.com/docs/git-stash#Documentation/git-stash.txt-push-p--patch-S--staged-k--no-keep-index-u--include-untracked-a--all-q--quiet-m--messageltmessagegt--pathspec-from-fileltfilegt--pathspec-file-nul--ltpathspecgt82308203 <code>git stash push ''pathspec''</code>] |
||
+ | | Save your local modifications to a new stash entry and roll them back to HEAD (in the working tree and in the index) || |
||
+ | |- |
||
+ | | || [http://git-scm.com/docs/git-stash#Documentation/git-stash.txt-pop--index-q--quietltstashgt <code>git stash pop ''stash''</code>] |
||
+ | | Remove a single stashed state from the stash list and apply it on top of the current working tree state || |
||
+ | |- |
||
+ | | || [http://git-scm.com/docs/git-stash#Documentation/git-stash.txt-drop-q--quietltstashgt <code>git stash ''stash''</code>] |
||
+ | | Remove a single stash entry from the list of stash entries. || |
||
+ | |- |
||
+ | | || [http://git-scm.com/docs/git-stash#Documentation/git-stash.txt-clear <code>git clear</code>] |
||
+ | | Remove all the stash entries. || |
||
+ | |- |
||
+ | | Patching || [https://git-scm.com/docs/git-rebase <code>git rebase</code>] |
||
+ | | Reapply commits on top of another base tip || |
||
+ | |- |
||
+ | | || [https://git-scm.com/docs/git-revert <code>git revert</code>] |
||
+ | | Revert some existing commits || Requires your working tree to be clean (no modifications from the HEAD commit) |
||
+ | |- |
||
+ | | Administration || [https://git-scm.com/docs/git-clean <code>git clean</code>] |
||
+ | | Remove untracked files from the working tree || |
||
+ | |- |
||
+ | | || [https://git-scm.com/docs/git-archive <code>git archive</code>] |
||
+ | | Create an archive of files from a named tree || <code>git archive -o latest.zip HEAD</code> |
||
+ | |- |
||
+ | | Plumbing || [https://git-scm.com/docs/git-ls-files <code>git ls-files</code>] |
||
+ | | Show information about files in the index and the working tree || <code><nowiki>git ls-files | wc -l</nowiki></code> |
||
+ | |- |
||
+ | | || [https://git-scm.com/docs/git-show-ref <code>git show-ref</code>] |
||
+ | | List references in a local repository || |
||
+ | |- |
||
+ | | Guides || [http://git-scm.com/docs/gitignore <code>gitignore</code>] |
||
+ | | || (<code>$HOME/.config/git/ignore, $GIT_DIR/info/exclude, .gitignore</code>) |
||
+ | |- |
||
+ | | Misc || [https://git-scm.com/docs/git-svn <code>git svn</code>] |
||
+ | | Bidirectional operation between a Subversion repository and Git || |
||
|} |
|} |
||
+ | ===Ref=== |
||
− | * [http://git-scm.com/docs Git Reference] |
||
+ | |||
− | ** [https://git-scm.com/docs/git-config#_variables Git configuration variables] |
||
+ | <blockquote class='bared'>A name that begins with <code>refs/</code> (e.g. <code>refs/heads/master</code>) that points to an object name or another ref.</blockquote> |
||
− | ** [https://git-scm.com/docs/revisions Revisions] |
||
+ | |||
− | ** [https://git-scm.com/docs/gitignore#_pattern_format <code>gitignore</code> Pattern Format] |
||
+ | * [http://wiki.eclipse.org/EGit/User_Guide#Git_References Git References(Refs)] |
||
− | * [https://git-scm.com/book/en/v2 ''Pro Git''] |
||
− | + | * [https://git-scm.com/book/en/v2/Git-Internals-Git-References Git Internals - Git References] |
|
+ | |||
− | ** [https://git-scm.com/book/en/v2/Git-Branching-Branches-in-a-Nutshell Git Branching] |
||
+ | {| class='wikitable' |
||
− | ** [https://git-scm.com/book/en/v2/Git-Branching-Remote-Branches '''Remote Branches'''] |
||
+ | ! Type !! Format !! Example !! Remarks |
||
− | * [https://help.github.com/categories/54/articles GitHub Bootcamp] |
||
+ | |- |
||
− | ** As of Nov. 1st 2012, one important thing is missing. That is sharing the project in Eclipse, after cloning the fork in the server. Maybe it could be a defect of Eclipse, not a miss of the article. |
||
+ | | Local branches || <tt>refs/heads/...</tt> || <tt>refs/heads/2.x</tt>, <tt>refs/heads/3.x</tt> || |
||
+ | |- |
||
+ | | Remote tracking branches || <tt>refs/remotes/...</tt> || <tt>refs/remotes/origin/master</tt>, <tt>refs/remotes/upstream/master</tt> || |
||
+ | |- |
||
+ | | Tags || <tt>refs/tags/...</tt> || <tt>refs/tags/v0.9</tt>, <tt>refs/tags/v1.5.RELEASE</tt>, <tt>refs/tags/v2.0.GA</tt> || |
||
+ | |} |
||
+ | |||
+ | <blockquote><code>$ git show-ref</code></blockquote> |
||
+ | |||
+ | <syntaxhighlight lang='text' enclose='div'> |
||
+ | |||
+ | +--- HEAD |
||
+ | | |
||
+ | +--- FETCH_HEAD |
||
+ | | |
||
+ | +--- ORIG_HEAD |
||
+ | | |
||
+ | .git/ ---+--- refs/ ---+--- heads/ ---+--- main |
||
+ | | | |
||
+ | | +--- next |
||
+ | | |
||
+ | +--- tags/ ----+--- v0.9 |
||
+ | | | |
||
+ | | +--- v1.0 |
||
+ | | | |
||
+ | | +--- v1.1 |
||
+ | | |
||
+ | +--- remotes/ ---+--- origin/ --- main |
||
+ | | | |
||
+ | | +--- origin/ --- HEAD |
||
+ | | | |
||
+ | | +--- upstream/ --- main |
||
+ | | |
||
+ | +--- stash/ |
||
+ | </syntaxhighlight> |
||
+ | |||
+ | ====Reserved Refs==== |
||
+ | |||
+ | {| class='wikitable' |
||
+ | ! Reserved !! Full !! Description || Remarks |
||
+ | |- |
||
+ | | <code>master</code> || <code>refs/heads/master</code> || local master branch || |
||
+ | |- |
||
+ | | <code>origin/master</code> || <code>refs/remotes/origin/master</code> || || |
||
+ | |- |
||
+ | | <code>v1.0.1</code> || <code>refs/tags/v1.0.1</code> || || |
||
+ | |- |
||
+ | | <code>HEAD</code> || || currently checkout commit points out the last commit in the current checkout branch. || <code>cat .git/HEAD</code> |
||
+ | |- |
||
+ | | <code>FETCH_HEAD</code> || || the result of the last fetch operation || <code>cat .git/FETCH_HEAD</code> |
||
+ | |- |
||
+ | | <code>ORIG_HEAD</code> || || the commit that was checked out before a merge or rebase operation was started || <code>cat .git/ORIG_HEAD</code> |
||
+ | |} |
||
+ | |||
+ | =====<tt>HEAD</tt>===== |
||
+ | |||
+ | * [https://git-scm.com/book/en/v2/Git-Internals-Git-References#ref_the_ref The HEAD] |
||
+ | <syntaxhighlight lang='bash' enclose='div'> |
||
+ | $ cat .git/HEAD |
||
+ | ref: refs/heads/master |
||
+ | $ git checkout test |
||
+ | ... |
||
+ | $ cat .git/HEAD |
||
+ | ref: refs/heads/test |
||
+ | </syntaxhighlight> |
||
+ | |||
+ | * [https://www.javatpoint.com/git-head Git Head] |
||
+ | ** The HEAD points out the last commit in the current checkout branch. It is like a pointer to any reference. |
||
+ | ** <code>$ git show HEAD</code> |
||
+ | |||
+ | ===Refspec=== |
||
+ | |||
+ | <blockquote class='bared'>Used by <code>fetch</code> and <code>push</code> to describe the mapping between remote ref and local ref.</blockquote> |
||
+ | |||
+ | * [http://git-scm.com/docs/git-push#Documentation/git-push.txt-ltrefspecgt82308203 <code>git-push</code> <tt>refspec</tt>] |
||
+ | * [http://git-scm.com/docs/git-fetch#Documentation/git-fetch.txt-ltrefspecgt <code>git-fetch</code> <tt>refspec</tt>] |
||
+ | * [http://git-scm.com/docs/git-pull#Documentation/git-pull.txt-ltrefspecgt <code>git-pull</code> <tt>refspec</tt>] |
||
+ | |||
+ | * [https://wiki.eclipse.org/EGit/User_Guide#Push_Refspecs Push Refspecs] |
||
+ | * [https://wiki.eclipse.org/EGit/User_Guide#Fetch_Refspecs Fetch Refspecs] |
||
+ | |||
+ | ===Configuration=== |
||
+ | |||
+ | * [https://git-scm.com/docs/git-config#_variables Git configuration variables] |
||
+ | |||
+ | {| class='wikitable sortable' |
||
+ | ! Variable !! Data Type !! Description !! Default !! Remarks |
||
+ | |- |
||
+ | | [https://git-scm.com/docs/git-config#Documentation/git-config.txt-initdefaultBranch <code>init.defaultBranch</code>] |
||
+ | | string || Allows overriding the default branch name || || |
||
+ | |- |
||
+ | | [https://git-scm.com/docs/git-config#Documentation/git-config.txt-pushfollowTags <code>push.followTags</code>] |
||
+ | | boolean || If set to true enable <tt>--follow-tags</tt> option by default. || <tt>false</tt> || <tt>--no-follow-tags</tt> |
||
+ | |} |
||
+ | |||
+ | * Common global configuration |
||
+ | <syntaxhighlight lang='bash' enclose='div'> |
||
+ | $ git config --global init.defaultbranch main |
||
+ | $ git config --global core.autocrlf false |
||
+ | |||
+ | $ git config --global user.name ... |
||
+ | $ git config --global user.email ... |
||
+ | $ git config --global author.name ... |
||
+ | $ git config --global author.email ... |
||
+ | $ git config --global committer.name ... |
||
+ | $ git config --global committer.email ... |
||
+ | </syntaxhighlight> |
||
+ | |||
+ | ===Model=== |
||
+ | |||
* [http://ndpsoftware.com/git-cheatsheet.html Git Cheatsheet] |
* [http://ndpsoftware.com/git-cheatsheet.html Git Cheatsheet] |
||
− | + | * [https://backlog.com/git-tutorial/git-workflow/ Git Workflow] |
|
+ | |||
− | ** [http://ndpsoftware.com/git-cheatsheet.html#loc=local_repo; Local Repository] |
||
+ | ====File State-chart==== |
||
− | ** [http://ndpsoftware.com/git-cheatsheet.html#loc=remote_repo; Upstream Repository] |
||
+ | |||
− | * [https://www.atlassian.com/git/tutorial Git Tutorials] |
||
+ | * [https://git-scm.com/book/en/v2/Git-Basics-Recording-Changes-to-the-Repository Recording Changes to the Repository] |
||
− | * [https://www.atlassian.com/git/workflows Git Workflows] |
||
+ | |||
− | * [http://wiki.eclipse.org/EGit EGit User Guide] |
||
+ | <syntaxhighlight lang='text' enclose='div'> |
||
− | ** [http://wiki.eclipse.org/EGit/User_Guide#Git_References Git References(Refs)] |
||
+ | |||
− | ** [http://wiki.eclipse.org/EGit/User_Guide#Remotes Remotes] |
||
+ | Untracked Modified Staged Committed |
||
+ | | | | | |
||
+ | +- add ------------|---------------->| | |
||
+ | | | | | |
||
+ | | +- add ---------->| | |
||
+ | | | | | |
||
+ | | | +- commit ----->| |
||
+ | | | | | |
||
+ | | | | | |
||
+ | | |<----------------|-------- edit -+ |
||
+ | | | | | |
||
+ | |<-----------------+-----------------+------ remove -| |
||
+ | | | | | |
||
+ | |||
+ | |||
+ | * Tracked = Modified | Staged | Committed |
||
+ | </syntaxhighlight> |
||
+ | |||
+ | <syntaxhighlight lang='text' enclose='div'> |
||
+ | |||
+ | +-----------+ +---------+ +------------+ |
||
+ | | Untracked | ---add---> | Staged | <---add--- | Modified | |
||
+ | |(workspace)| | (index) | |(workspace)| |
||
+ | +-----------+ +---------+ +------------+ |
||
+ | | ^ |
||
+ | | | |
||
+ | commit edit |
||
+ | | | |
||
+ | | +-----------+ | |
||
+ | +---> | Committed | ---+ |
||
+ | +-----------+ |
||
+ | |||
+ | </syntaxhighlight> |
||
+ | |||
+ | ====Areas==== |
||
+ | |||
+ | {| class='wikitable' |
||
+ | ! Area !! Role !! Description !! Remarks |
||
+ | |- |
||
+ | | Workspace || Working directory || Consists of files that you are currently working on. || Local checkout |
||
+ | |- |
||
+ | | Index || Staging area, Cache || Where commits are prepared. || |
||
+ | |- |
||
+ | | Stash || || A place to hide modifications while you work on something else || |
||
+ | |- |
||
+ | | Local Repository || || || |
||
+ | |- |
||
+ | | Upstream Repository || || || |
||
+ | |} |
||
+ | |||
+ | ====Branching==== |
||
+ | |||
+ | <syntaxhighlight lang='text' enclose='div'> |
||
+ | |||
+ | $ git commit -a -m "..." |
||
+ | |||
+ | << master, HEAD >> |
||
+ | | |
||
+ | +----+ +----+ +----+ |
||
+ | | c1 | <----- | c2 | <----- | c3 | |
||
+ | +----+ +----+ +----+ |
||
+ | |||
+ | $ git branch iss31 # branch to work on issue 31 - new feature |
||
+ | |||
+ | << master, HEAD >> |
||
+ | | |
||
+ | +----+ +----+ +----+ |
||
+ | | c1 | <----- | c2 | <----- | c3 | |
||
+ | +----+ +----+ +----+ |
||
+ | | |
||
+ | << iss31 >> |
||
+ | |||
+ | $ git checkout iss31 |
||
+ | |||
+ | << master >> |
||
+ | | |
||
+ | +----+ +----+ +----+ |
||
+ | | c1 | <----- | c2 | <----- | c3 | |
||
+ | +----+ +----+ +----+ |
||
+ | | |
||
+ | << iss31, HEAD >> |
||
+ | |||
+ | $ # edits or adds some files |
||
+ | $ git commit -a -m ... |
||
+ | |||
+ | << master >> |
||
+ | | |
||
+ | +----+ +----+ +----+ +----+ |
||
+ | | c1 | <----- | c2 | <----- | c3 | <----- | c4 | |
||
+ | +----+ +----+ +----+ +----+ |
||
+ | | |
||
+ | << iss31, HEAD >> |
||
+ | |||
+ | $ # a simple bug is found, create anothter branch for hotfix on 'master' |
||
+ | $ git checkout master |
||
+ | $ git checkout -b hotfix # same with 'git branch hotfix; git checkout hotfix' |
||
+ | |||
+ | << master, HEAD >> |
||
+ | | |
||
+ | +----+ +----+ +----+ +----+ |
||
+ | | c1 | <----- | c2 | <----- | c3 | <----- | c4 | |
||
+ | +----+ +----+ +----+ +----+ |
||
+ | | |
||
+ | << iss31 >> |
||
+ | |||
+ | << hotfix, HEAD >> |
||
+ | << master >> |
||
+ | | |
||
+ | +----+ +----+ +----+ +----+ |
||
+ | | c1 | <----- | c2 | <----- | c3 | <----- | c4 | |
||
+ | +----+ +----+ +----+ +----+ |
||
+ | | |
||
+ | << iss31 >> |
||
+ | |||
+ | $ # edits some files to fix the bug |
||
+ | $ git commit -a -m ... |
||
+ | |||
+ | << hotfix, HEAD >> |
||
+ | | |
||
+ | +----+ |
||
+ | << master >> +-- | c5 | |
||
+ | | | +----+ |
||
+ | +----+ +----+ +----+ <-----+ |
||
+ | | c1 | <----- | c2 | <----- | c3 | |
||
+ | +----+ +----+ +----+ <-----+ |
||
+ | | +----+ |
||
+ | +-- | c4 | |
||
+ | +----+ |
||
+ | | |
||
+ | << iss31 >> |
||
+ | |||
+ | $ # after successful testing on hotfix, merge 'hotfix' to 'master'. remove 'hotfix' after merge |
||
+ | $ git checkout master |
||
+ | $ git merge hotfix # 'master' fast-forwarded |
||
+ | $ git branch --delete hotfix # --delete == -d |
||
+ | |||
+ | << hotfix >> |
||
+ | << master, HEAD >> |
||
+ | | |
||
+ | +----+ |
||
+ | +-- | c5 | |
||
+ | | +----+ |
||
+ | +----+ +----+ +----+ <-----+ |
||
+ | | c1 | <----- | c2 | <----- | c3 | |
||
+ | +----+ +----+ +----+ <-----+ |
||
+ | | +----+ |
||
+ | +-- | c4 | |
||
+ | +----+ |
||
+ | | |
||
+ | << iss31 >> |
||
+ | |||
+ | << master, HEAD >> |
||
+ | | |
||
+ | +----+ |
||
+ | +-- | c5 | |
||
+ | | +----+ |
||
+ | +----+ +----+ +----+ <-----+ |
||
+ | | c1 | <----- | c2 | <----- | c3 | |
||
+ | +----+ +----+ +----+ <-----+ |
||
+ | | +----+ |
||
+ | +-- | c4 | |
||
+ | +----+ |
||
+ | | |
||
+ | << iss31 >> |
||
+ | |||
+ | $ # after hotfix, works on 'iss31' branch with other commits |
||
+ | $ git checkout iss31 |
||
+ | |||
+ | << master >> |
||
+ | | |
||
+ | +----+ |
||
+ | +-- | c5 | |
||
+ | | +----+ |
||
+ | +----+ +----+ +----+ <-----+ |
||
+ | | c1 | <----- | c2 | <----- | c3 | |
||
+ | +----+ +----+ +----+ <-----+ |
||
+ | | +----+ +----+ +----+ |
||
+ | +-- | c4 | <--- | c6 | <--- | c7 | |
||
+ | +----+ +----+ +----+ |
||
+ | | |
||
+ | << iss31, HEAD >> |
||
+ | |||
+ | $ # when 'iss31' implemented successfully |
||
+ | $ git checkout mater |
||
+ | $ git merge iss31 # if no conflict, simple three-way merge with another new commit |
||
+ | |||
+ | << master, HEAD >> |
||
+ | | |
||
+ | +----+ <------------------------------- +----+ |
||
+ | +-- | c5 | | c8 | |
||
+ | | +----+ +----- +----+ |
||
+ | +----+ +----+ +----+ <-----+ | | |
||
+ | | c1 | <----- | c2 | <----- | c3 | | << iss31 >> |
||
+ | +----+ +----+ +----+ <-----+ | |
||
+ | | +----+ +----+ +----+ | |
||
+ | +-- | c4 | <--- | c6 | <--- | c7 | --+ |
||
+ | +----+ +----+ +----+ |
||
+ | </syntaxhighlight> |
||
+ | |||
+ | * [https://git-scm.com/docs/git-checkout#_detached_head Detached HEAD] |
||
+ | |||
+ | ====Commands==== |
||
+ | |||
+ | {| class='wikitable' |
||
+ | | [https://git-scm.com/docs/git-merge/2.27.0 <tt>merge</tt>] |
||
+ | | <syntaxhighlight lang='text' enclose='div' style='border:0'> |
||
+ | |||
+ | A---B---C topic |
||
+ | / |
||
+ | D---E---F---G master |
||
+ | |||
+ | </syntaxhighlight> |
||
+ | | <tt>(master)$ git merge --no-ff topic</tt> |
||
+ | | <syntaxhighlight lang='text' enclose='div' style='border:0'> |
||
+ | |||
+ | A---B---C topic |
||
+ | / \ |
||
+ | D---E---F---G---H master |
||
+ | |||
+ | </syntaxhighlight> |
||
+ | |- |
||
+ | | [https://git-scm.com/docs/git-reset#Documentation/git-reset.txt-emgitresetemltmodegtltcommitgt <tt>reset --hard</tt>] |
||
+ | | <syntaxhighlight lang='text' enclose='div' style='border:0'> |
||
+ | |||
+ | A---B---C topic |
||
+ | / |
||
+ | D---E---F---G---H master |
||
+ | |||
+ | </syntaxhighlight> |
||
+ | | <tt>(master)$ git reset --hard HEAD~2 |
||
+ | | <syntaxhighlight lang='text' enclose='div' style='border:0'> |
||
+ | |||
+ | A---B---C topic |
||
+ | / |
||
+ | D---E---F master |
||
+ | |||
+ | </syntaxhighlight> |
||
+ | |- |
||
+ | | <tt>revert</tt> || || || |
||
+ | |- |
||
+ | | <tt>restore</tt> || || || |
||
+ | |- |
||
+ | | [https://git-scm.com/docs/git-rebase/2.27.0 <tt>rebase</tt>] |
||
+ | | <syntaxhighlight lang='text' enclose='div' style='border:0'> |
||
+ | |||
+ | A---B---C topic |
||
+ | / |
||
+ | D---E---F---G master |
||
+ | |||
+ | </syntaxhighlight> |
||
+ | | <tt>$ git rebase master topic</tt> |
||
+ | | <syntaxhighlight lang='text' enclose='div' style='border:0'> |
||
+ | |||
+ | A'--B'--C' topic |
||
+ | / |
||
+ | D---E---F---G master |
||
+ | |||
+ | </syntaxhighlight> |
||
+ | |- |
||
+ | | |
||
+ | | <syntaxhighlight lang='text' enclose='div' style='border:0'> |
||
+ | |||
+ | A---B---C topic |
||
+ | / |
||
+ | D---E---A'---F master |
||
+ | |||
+ | </syntaxhighlight> |
||
+ | | <tt>$ git rebase master topic</tt> |
||
+ | | <syntaxhighlight lang='text' enclose='div' style='border:0'> |
||
+ | |||
+ | B'---C' topic |
||
+ | / |
||
+ | D---E---A'---F master |
||
+ | |||
+ | </syntaxhighlight> |
||
+ | |} |
||
==Readings== |
==Readings== |
||
+ | |||
+ | {| class='wikitable' |
||
+ | ! Topic !! Reading !! Remark |
||
+ | |- |
||
+ | | Stashing || [https://www.atlassian.com/git/tutorials/saving-changes/git-stash Git stash] (Bitbucket) || |
||
+ | |} |
||
* [http://stackoverflow.com/questions/4684352/whats-a-fast-forward-in-git What's a “fast-forward” in Git?] |
* [http://stackoverflow.com/questions/4684352/whats-a-fast-forward-in-git What's a “fast-forward” in Git?] |
||
Line 85: | Line 808: | ||
* [http://stackoverflow.com/questions/4044368/what-does-tree-ish-mean-in-git/ What does tree-ish mean in Git?](Oct 28 '10) |
* [http://stackoverflow.com/questions/4044368/what-does-tree-ish-mean-in-git/ What does tree-ish mean in Git?](Oct 28 '10) |
||
* [https://help.github.com/articles/ignoring-files/ Ignoring files] |
* [https://help.github.com/articles/ignoring-files/ Ignoring files] |
||
− | * [https://stackoverflow.com/questions/7803689/gitignore-ignore-all-files-in-folder-hierarchy-except-one-specific-filetype gitignore: Ignore all files in folder hierarchy except one specific filetype]( |
+ | * [https://stackoverflow.com/questions/7803689/gitignore-ignore-all-files-in-folder-hierarchy-except-one-specific-filetype gitignore: Ignore all files in folder hierarchy except one specific filetype] (Oct 18 '11) |
+ | * [https://stackoverflow.com/questions/2820255/how-do-negated-patterns-work-in-gitignore How do negated patterns work in .gitignore?] (May 12 '10) |
||
+ | ** <code>/excluded/*</code>, <code>!/excluded/included</code> |
||
* [https://felipec.wordpress.com/2014/05/29/git-v2-0-0/ Git v2.0.0, what changed, and why should you care] (2014/05/29) |
* [https://felipec.wordpress.com/2014/05/29/git-v2-0-0/ Git v2.0.0, what changed, and why should you care] (2014/05/29) |
||
* [https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/ '''Adding an existing project to GitHub using the command line'''] |
* [https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/ '''Adding an existing project to GitHub using the command line'''] |
||
Line 98: | Line 823: | ||
* [https://stackoverflow.com/questions/38239521/what-is-the-parent-of-a-git-commit-how-can-there-be-more-than-one-parent-to-a-g What is the parent of a git commit? How can there be more than one parent to a git commit?] (Jul 7 '16) |
* [https://stackoverflow.com/questions/38239521/what-is-the-parent-of-a-git-commit-how-can-there-be-more-than-one-parent-to-a-g What is the parent of a git commit? How can there be more than one parent to a git commit?] (Jul 7 '16) |
||
− | === |
+ | ===Basic Snapshotting=== |
+ | |||
+ | <blockquote class='bared'><tt>add</tt>, <tt>status</tt>, <tt>diff</tt>, <tt>commit</tt>, <tt>restore</tt>, <tt>reset</tt></blockquote> |
||
+ | |||
+ | ====<tt>status</tt>==== |
||
* [https://git-scm.com/book/en/v2/Git-Basics-Recording-Changes-to-the-Repository Recording Changes to the Repository] |
* [https://git-scm.com/book/en/v2/Git-Basics-Recording-Changes-to-the-Repository Recording Changes to the Repository] |
||
* [https://howtogit.net/concepts/types-of-changes.html Difference between untracked, unstaged and staged changes] |
* [https://howtogit.net/concepts/types-of-changes.html Difference between untracked, unstaged and staged changes] |
||
− | === |
+ | ====<tt>diff</tt>==== |
− | * [https://stackoverflow.com/questions/ |
+ | * [https://stackoverflow.com/questions/3338126/how-to-diff-the-same-file-between-two-different-commits-on-the-same-branch How to diff the same file between two different commits on the same branch?] (Jul 26 '10) |
+ | * [https://stackoverflow.com/questions/3211809/git-diff-between-given-two-tags Git diff between given two tags] (Jul 9 '10) |
||
− | ** <code>git branch -vv</code>, <code>git status</code> |
||
+ | * [https://stackoverflow.com/questions/21101572/git-diff-between-file-in-local-repo-and-origin/21101644 git: diff between file in local repo and origin] (Jan 13 '14) |
||
− | * [https://help.github.com/articles/pushing-to-a-remote/ Pushing to a remote] |
||
+ | ** <tt>$ git fetch; git diff --summary master origin/master</tt> |
||
− | ** ''By default, and without additional parameters, <code>git push</code> sends all matching branches that have the same names as remote branches.'' |
||
+ | * [https://stackoverflow.com/questions/1552340/how-to-list-only-the-names-of-files-that-changed-between-two-commits How to list only the names of files that changed between two commits] (Oct 12, 2009) |
||
+ | ** <tt>git diff --name-only HEAD~10 HEAD~5</tt> |
||
− | === |
+ | ====<tt>reset</tt>==== |
+ | |||
+ | * [https://git-scm.com/docs/git#_reset_restore_and_revert Reset, restore and revert] |
||
+ | {| class='wikitable' |
||
+ | ! command !! Description !! Remark |
||
+ | |- |
||
+ | | <tt>restore</tt> || about restoring files in the working tree from either the index or another commit. || does not update your branch |
||
+ | |- |
||
+ | | <tt>reset</tt> || updating your branch, moving the tip in order to add or remove commits from the branch. || can also be used to restore the index, overlapping with git restore. |
||
+ | |- |
||
+ | | <tt>revert</tt> || about making a new commit that reverts the changes made by other commits. || |
||
+ | |} |
||
+ | |||
+ | <blockquote class='bared'><tt>git revert</tt> is used to record some new commits to reverse the effect of some earlier commits (often only a faulty one). If you want to throw away all uncommitted changes in your working directory, you should see <tt>git-reset</tt>, particularly the --hard option. If you want to extract specific files as they were in another commit, you should see <tt>git-restore</tt>, specifically the --source option. Take care with these alternatives as both will discard uncommitted changes in your working directory.</blockquote> |
||
+ | |||
+ | * [https://git-scm.com/docs/git-reset#Documentation/git-reset.txt-Undocommitspermanently Undo commits permanently] |
||
+ | * [https://stackoverflow.com/questions/40245767/delete-commit-on-gitlab '''Delete commit on gitlab'''] (Oct 25, 2016) |
||
+ | ** <code>git reset --hard CommitId</code>, <code>git push -f origin master</code> |
||
+ | |||
+ | ====<tt>rm</tt>==== |
||
+ | |||
+ | * [https://stackoverflow.com/questions/40606646/git-treats-folder-as-file-and-ignores-all-subfolders-and-files Git treats folder as file and ignores all subfolders and -files] (Nov 15 '16) |
||
+ | |||
+ | ===Branching=== |
||
+ | |||
+ | <blockquote class='bared'><tt>branch</tt>, <tt>checkout</tt>, <tt>switch</tt>, <tt>merge</tt>, <tt>log</tt>, <tt>tag</tt></blockquote> |
||
+ | |||
+ | * [https://nvie.com/posts/a-successful-git-branching-model/ A successful Git branching model] (January 05, 2010) |
||
+ | |||
+ | ====<tt>branch</tt>==== |
||
+ | |||
+ | <blockquote class='bared'> |
||
+ | * A '''branch''' in Git is simply a lightweight '''movable pointer''' to one of these commits. |
||
+ | * Every time you commit, the master branch pointer '''moves forward''' automatically. |
||
+ | * '''<tt>HEAD</tt>''' is a pointer to the local branch you’re currently on. |
||
+ | </blockquote> |
||
+ | |||
+ | {| class='wikitable' |
||
+ | ! Term !! Description !! Remark |
||
+ | |- |
||
+ | | Remote-tracking Branch || || |
||
+ | |- |
||
+ | | Upstream Branch || || |
||
+ | |} |
||
* [https://stackoverflow.com/questions/9257533/what-is-the-difference-between-origin-and-upstream-on-github What is the difference between origin and upstream on GitHub?] (Feb 13 '12) |
* [https://stackoverflow.com/questions/9257533/what-is-the-difference-between-origin-and-upstream-on-github What is the difference between origin and upstream on GitHub?] (Feb 13 '12) |
||
Line 117: | Line 891: | ||
* [https://stackoverflow.com/questions/1519006/how-do-you-create-a-remote-git-branch How do you create a remote Git branch?] (Oct 5 '09) |
* [https://stackoverflow.com/questions/1519006/how-do-you-create-a-remote-git-branch How do you create a remote Git branch?] (Oct 5 '09) |
||
** <code>git push <remote-name> <local-branch-name>:<remote-branch-name></code> |
** <code>git push <remote-name> <local-branch-name>:<remote-branch-name></code> |
||
+ | * [https://stackoverflow.com/questions/520650/make-an-existing-git-branch-track-a-remote-branch Make an existing Git branch track a remote branch?](Feb 6, 2009) |
||
+ | ** <code>git branch -u upstream/foo foo</code> or <code>git branch --set-upstream-to=upstream/foo foo</code> |
||
+ | * [https://linuxize.com/post/how-to-rename-local-and-remote-git-branch/ How To Rename a Local and Remote Git Branch] (Feb 18, 2020) |
||
+ | ** <tt>git branch -m <i>name</i></tt>, <tt>git push origin --delete <i>name</i></tt> |
||
+ | * [https://stackoverflow.com/questions/424071/how-to-list-all-the-files-in-a-commit How to list all the files in a commit?] (Jan 8 '09) |
||
+ | ** <tt>git show --name-only -1</tt>, <tt>git log --name-only -1</tt> |
||
− | === |
+ | ====<tt>checkout</tt>==== |
* [https://stackoverflow.com/questions/35979642/how-to-checkout-remote-git-tag How to checkout remote git tag] (Mar 14 '16) |
* [https://stackoverflow.com/questions/35979642/how-to-checkout-remote-git-tag How to checkout remote git tag] (Mar 14 '16) |
||
Line 125: | Line 905: | ||
** <code>git checkout master</code> |
** <code>git checkout master</code> |
||
+ | * [https://stackoverflow.com/questions/2364147/how-to-get-just-one-file-from-another-branch/2364223 '''How to get just one file from another branch?'''] (asked Mar 2 2010) |
||
− | ===Tag=== |
||
+ | ** <code>git checkout experiment -- app.js</code> |
||
+ | * [https://jasonrudolph.com/blog/2009/02/25/git-tip-how-to-merge-specific-files-from-another-branch/ Git tip: How to "merge" specific files from another branch] (February 25, 2009) |
||
+ | ** <code>git checkout <i>source_branch</i> <i>paths</i></code> |
||
+ | * [https://stackoverflow.com/questions/10784523/how-do-i-merge-changes-to-a-single-file-rather-than-merging-commits How do I merge changes to a single file, rather than merging commits?] ( May 28, 2012) |
||
+ | |||
+ | * [https://adamtheautomator.com/git-checkout-remote-branch/ How to Check out a Remote Git Branch <nowiki>[Step-by-Step]</nowiki>] (30 March 2021) |
||
+ | ** ''A Git repository itself may have multiple remotes, but a branch can only reference a single remote.'' |
||
+ | ** ''The '''fetch''' command will connect to the remote repository and retrieve a list of all available branches.'' |
||
+ | ** <code>git checkout RemoteBranch</code> |
||
+ | * [https://www.git-tower.com/learn/git/faq/checkout-remote-branch git checkout a Remote Branch] |
||
+ | ** ''In order to see this newly published branch, you will have to perform a simple "git fetch" for the remote.'' |
||
+ | ** <syntaxhighlight class='inline' inline lang='bash'>$ git checkout --track origin/newsletter</syntaxhighlight> |
||
+ | |||
+ | ====<tt>merge</tt>==== |
||
+ | |||
+ | * [https://www.atlassian.com/git/tutorials/using-branches/git-merge Git Merge] |
||
+ | |||
+ | * [https://unfuddle.com/stack/tips-tricks/git-cancel-merge/ How do I cancel a git merge?] |
||
+ | ** <code>git reset --hard HEAD</code> or <code>git merge --abort</code> |
||
+ | |||
+ | ====<tt>tag</tt>==== |
||
− | * [https://stackoverflow.com/questions/5195859/how-to-push-a-tag-to-a-remote-repository-using-git How to push a tag to a remote repository using Git?] (Mar 4 '11) |
||
− | ** <code>git push origin --tags</code> |
||
* [https://stackoverflow.com/questions/5358336/how-to-list-all-tags-along-with-the-full-message-in-git How to list all tags along with the full message in git?] (Mar 18 '11) |
* [https://stackoverflow.com/questions/5358336/how-to-list-all-tags-along-with-the-full-message-in-git How to list all tags along with the full message in git?] (Mar 18 '11) |
||
** <code>git tag -l -n9</code> |
** <code>git tag -l -n9</code> |
||
+ | * [https://stackoverflow.com/questions/1862423/how-to-tell-which-commit-a-tag-points-to-in-git How to tell which commit a tag points to in Git?] (Dec 7, 2009) |
||
+ | ** <tt>$ git show-ref --tags</tt> |
||
+ | ** <tt>$ git show ''tagname''</tt> |
||
+ | * [https://stackoverflow.com/questions/5195859/how-to-push-a-tag-to-a-remote-repository-using-git How to push a tag to a remote repository using Git?] (Mar 4 '11) |
||
+ | ** <code>git push origin --tags</code> |
||
+ | * [https://stackoverflow.com/questions/5195859/how-do-you-push-a-tag-to-a-remote-repository-using-git How do you push a tag to a remote repository using Git?] (Mar 4 '11) |
||
+ | ** <tt>git push origin <tag_name></tt> |
||
+ | * [https://devconnected.com/how-to-delete-local-and-remote-tags-on-git/ How To Delete Local and Remote Tags on Git] |
||
+ | ** <tt>$ git push --delete origin ''tag-name''</tt> |
||
− | === |
+ | ===Sharing=== |
+ | <blockquote class='bared'><tt>fetch</tt>, <tt>pull</tt>, <tt>push</tt>, <tt>remote</tt></blockquote> |
||
− | * [https://help.github.com/articles/about-git-subtree-merges/ '''About Git subtree merges'''] |
||
− | ** to manage multiple projects within a single repository |
||
− | * [https://medium.com/@porteneuve/mastering-git-subtrees-943d29a798ec Mastering Git subtrees] |
||
+ | * [https://stackoverflow.com/questions/171550/find-out-which-remote-branch-a-local-branch-is-tracking Find out which remote branch a local branch is tracking] (Oct 5 '08) |
||
− | ===Diff=== |
||
+ | ** <code>git branch -vv</code>, <code>git status</code> |
||
+ | * [https://help.github.com/articles/pushing-to-a-remote/ Pushing to a remote] |
||
+ | ** ''By default, and without additional parameters, <code>git push</code> sends all matching branches that have the same names as remote branches.'' |
||
− | * [https://stackoverflow.com/questions/ |
+ | * [https://stackoverflow.com/questions/37770467/why-do-i-have-to-git-push-set-upstream-origin-branch Why do I have to "git push --set-upstream origin <branch>"?] (Jun 12, 2016) |
+ | ** <code>git push -u origin solaris</code> |
||
− | * [https://stackoverflow.com/questions/3211809/git-diff-between-given-two-tags Git diff between given two tags] (Jul 9 '10) |
||
+ | |||
− | * [https://stackoverflow.com/questions/21101572/git-diff-between-file-in-local-repo-and-origin/21101644 git: diff between file in local repo and origin] (Jan 13 '14) |
||
+ | * [https://www.git-tower.com/learn/git/faq/git-rename-master-to-main How to Rename the master branch to main in Git] |
||
− | ** <tt>$ git fetch; git diff --summary master origin/master</tt> |
||
+ | * [https://stackoverflow.com/questions/8839958/how-does-origin-head-get-set How does origin/HEAD get set?] (Jan 12, 2012) |
||
+ | ** ''origin's HEAD will only change if you or someone else actually changes it in the remote repository'' |
||
===Workflow=== |
===Workflow=== |
||
Line 153: | Line 964: | ||
* [https://nvie.com/posts/a-successful-git-branching-model/ A successful Git branching model] (January 05, 2010) |
* [https://nvie.com/posts/a-successful-git-branching-model/ A successful Git branching model] (January 05, 2010) |
||
+ | |||
+ | ===Hooks=== |
||
+ | |||
+ | * [https://www.atlassian.com/git/tutorials/git-hooks Git Hooks] |
||
===Tools=== |
===Tools=== |
||
Line 162: | Line 977: | ||
* [https://help.github.com/en/articles/changing-a-commit-message Changing a commit message] : <tt>git commit --amend</tt> |
* [https://help.github.com/en/articles/changing-a-commit-message Changing a commit message] : <tt>git commit --amend</tt> |
||
* [https://stackoverflow.com/questions/5064563/add-line-break-to-git-commit-m-from-the-command-line Add line break to 'git commit -m' from the command line] (Feb 21 '11) |
* [https://stackoverflow.com/questions/5064563/add-line-break-to-git-commit-m-from-the-command-line Add line break to 'git commit -m' from the command line] (Feb 21 '11) |
||
+ | * [https://www.serverlab.ca/scripting-programming/using-git-show-to-view-contents-of-files/ Using Git Show to View Contents of Files] (DECEMBER 14, 2019) |
||
+ | ** <code>git show <version>:<file></code> |
||
+ | |||
+ | ====Subtree==== |
||
+ | |||
+ | * [https://help.github.com/articles/about-git-subtree-merges/ '''About Git subtree merges'''] |
||
+ | ** to manage multiple projects within a single repository |
||
+ | * [https://medium.com/@porteneuve/mastering-git-subtrees-943d29a798ec Mastering Git subtrees] |
||
==Typical Usage== |
==Typical Usage== |
||
+ | ===Configuration=== |
||
− | ===Adding new items, committing and pushing them=== |
||
+ | |||
+ | ====List all configuration==== |
||
+ | |||
+ | <syntaxhighlight lang="bash" enclose="div"> |
||
+ | $ git config --list --show-scope --show-origin |
||
+ | |||
+ | </syntaxhighlight> |
||
+ | |||
+ | ===Snapshotting=== |
||
+ | |||
+ | ====Add, commit and push==== |
||
<syntaxhighlight lang="bash" enclose="div"> |
<syntaxhighlight lang="bash" enclose="div"> |
||
Line 174: | Line 1,008: | ||
$ git status . // confirms all changes are committed |
$ git status . // confirms all changes are committed |
||
$ git push // pushes changes in local repository onto the remote repository |
$ git push // pushes changes in local repository onto the remote repository |
||
+ | $ git log --name-only -1 // lists files in the last commit |
||
</syntaxhighlight> |
</syntaxhighlight> |
||
Line 187: | Line 1,022: | ||
</syntaxhighlight> |
</syntaxhighlight> |
||
+ | ====Creating local repository using existing artifacts==== |
||
− | ===Working with remote repositories=== |
||
+ | |||
+ | ... and pushing it to the remote bare repository |
||
<syntaxhighlight lang="bash" enclose="div"> |
<syntaxhighlight lang="bash" enclose="div"> |
||
+ | $ git init |
||
− | $ git remote -v // lists tracking repositories |
||
+ | $ git add . |
||
− | $ git remote add upstream https://github.com/jpmorganchase/quorum.git // add a new remote repository to track |
||
+ | $ git status . |
||
− | $ git branch -r // lists branches in tracking repositories |
||
+ | $ git commit -m "..." |
||
+ | $ git remote add origin https://github.com/.../....git |
||
+ | $ git push --set-upstream origin master |
||
+ | $ git remote -v |
||
</syntaxhighlight> |
</syntaxhighlight> |
||
− | === |
+ | ====Look around local repository==== |
<syntaxhighlight lang="bash" enclose="div"> |
<syntaxhighlight lang="bash" enclose="div"> |
||
+ | $ git status . // show the working tree status |
||
+ | $ git branch --all -vvvv // list both remote-tracking branches and local branches. |
||
+ | $ git tag -ln // list tags |
||
+ | $ git remote -v // list tracking repositories |
||
+ | $ git show-ref // list references in a local repository |
||
+ | $ git log origin/master -3 // lists 3 recent commits for remote branch 'origin/master' |
||
+ | $ git ls-files // show information about files in the index and the working tree |
||
+ | $ git config -l // list all variables set in config file, along with their values. |
||
+ | </syntaxhighlight> |
||
+ | |||
+ | ====Tracking changes==== |
||
+ | |||
+ | <syntaxhighlight lang="bash" enclose="div"> |
||
+ | $ git log master -3 // lists 3 recent commits for master branch |
||
+ | $ git log v2.0.2 -3 // lists 3 last commits before the tag of 'v2.0.2' |
||
+ | $ git log origin/master -1 // lists last commit of remote branch 'origin/master' |
||
+ | $ git log upstream/master -1 // lists last commit of remote branch 'upstream/master' |
||
+ | $ git log --name-only -1 // lists files in the last commit. |
||
+ | </syntaxhighlight> |
||
+ | |||
+ | ===Branching=== |
||
+ | |||
+ | ====Working with branches or tags==== |
||
+ | |||
+ | <syntaxhighlight lang="bash" enclose="div"> |
||
+ | $ git tag -ln // lists tags |
||
+ | $ git tag -a v2.0.2 -m "before new branch" // creates a new annotated tag(v2.0.2) |
||
+ | $ git tag origin v2.0.2 // push a tag to a remote |
||
+ | $ git push origin --tags // pushes all local tags to remote 'origin' |
||
+ | |||
$ git branch // lists branches |
$ git branch // lists branches |
||
$ git branch -a // lists both local and remote-tracking branches |
$ git branch -a // lists both local and remote-tracking branches |
||
$ git branch -avv // lists all branches showing hash and upstream branch if any |
$ git branch -avv // lists all branches showing hash and upstream branch if any |
||
+ | |||
− | $ git tag -ln // lists tags |
||
− | $ git tag -a v2.0.2 -m "before new branch" // creates a new tag(v2.0.2) |
||
$ git branch 1.1 // creates a new branch(1.1) from the master (branch) |
$ git branch 1.1 // creates a new branch(1.1) from the master (branch) |
||
$ git branch 2.0.2-ext v2.0.2 // creates a new branch(2.0.2-ext) from a tag(v2.0.2) |
$ git branch 2.0.2-ext v2.0.2 // creates a new branch(2.0.2-ext) from a tag(v2.0.2) |
||
+ | $ git push origin advanced:advanced // creates remote branch 'origin/advanced' from local branch 'advanced' |
||
+ | $ git push --set-upstream origin advanced // sets upstream(tracking) reference for current branch to |
||
+ | |||
$ git checkout release-1.1 // updates working tree to release-1.1 |
$ git checkout release-1.1 // updates working tree to release-1.1 |
||
$ git checkout -b gh-pages origin/gh-pages // copies remote branch to local repository |
$ git checkout -b gh-pages origin/gh-pages // copies remote branch to local repository |
||
− | $ git push origin advanced:advanced // creates remote branch 'origin/advanced' from local branch 'advanced' |
||
− | $ git push origin --tags // pushes all local tags to remote 'origin' |
||
</syntaxhighlight> |
</syntaxhighlight> |
||
− | === |
+ | ====Creating and pushing tag==== |
<syntaxhighlight lang="bash" enclose="div"> |
<syntaxhighlight lang="bash" enclose="div"> |
||
+ | $ git tag -a v1.0 -m "Ready to offer externally" |
||
− | $ git log master -3 // lists 3 recent commits for master branch |
||
+ | ... |
||
− | $ git log v2.0.2 -3 // lists 3 last commits before the tag of 'v2.0.2' |
||
+ | $ git push origin v1.0 |
||
− | $ git log origin/master -1 // lists last commit of remote branch 'origin/master' |
||
+ | ... |
||
− | $ git log upstream/master -1 // lists last commit of remote branch 'upstream/master' |
||
</syntaxhighlight> |
</syntaxhighlight> |
||
+ | ===Sharing=== |
||
− | ===Removing uncommitted changes on tracked files in the working tree=== |
||
+ | |||
+ | ====Managing remote repositories==== |
||
<syntaxhighlight lang="bash" enclose="div"> |
<syntaxhighlight lang="bash" enclose="div"> |
||
+ | $ git remote -v // lists tracking repositories |
||
− | $ git reset --hard // resets the index and working tree. Any changes to tracked files in the working tree since <commit> are discarded. |
||
+ | $ git remote add upstream https://github.com/jpmorganchase/quorum.git // add a new remote repository to track |
||
+ | $ git branch -r // lists branches in tracking repositories |
||
</syntaxhighlight> |
</syntaxhighlight> |
||
+ | ====Renaming branch at shared repository first==== |
||
− | ===Removing untracked files and directories in the working tree=== |
||
+ | |||
+ | <syntaxhighlight lang='text' enclose='div'> |
||
+ | The default branch has been renamed! |
||
+ | master is now named main |
||
+ | If you have a local clone, you can update it by running the following commands. |
||
+ | |||
+ | git branch -m master main |
||
+ | git fetch origin |
||
+ | git branch -u origin/main main |
||
+ | git remote set-head origin -a |
||
+ | </syntaxhighlight> |
||
+ | |||
+ | ===Undoing=== |
||
+ | |||
+ | {| class='wikitable' |
||
+ | ! Use-case !! Solution !! Example !! Remarks |
||
+ | |- |
||
+ | | Removing untracked files and directories || <code>git clean -dx</code> || || |
||
+ | |- |
||
+ | | Removing uncommitted changes on all the tracked files || <code>git reset --hard</code> || || |
||
+ | |- |
||
+ | | Undo commits permanently || <code>git reset --hard ''commit''</code> |
||
+ | | style='white-space:nowrap' | <code>git reset --hard HEAD</code> || |
||
+ | |- |
||
+ | | Removing uncommitted changes on a single or selected tracked files |
||
+ | | style='white-space:nowrap' | [https://git-scm.com/docs/git-checkout#Documentation/git-checkout.txt-emgitcheckoutem-f--ours--theirs-m--conflictltstylegtlttree-ishgt--ltpathspecgt82308203 <code>git checkout ''commit'' <nowiki>[</nowiki> -- <nowiki>]</nowiki> ''pathspec''</code>] |
||
+ | | || Overwrite both the index and the working tree that match the ''<tt>pathspec</tt>'' with the contents at the ''<tt>commit</tt>''. |
||
+ | |- |
||
+ | | Reverting committed changes || <code>git revert ''commit''</code> || <code>git revert HEAD</code> |
||
+ | | '''''<tt>revert</tt>''''' : go back to a previous state.<br/> |
||
+ | Instead of removing the commit from the project history, it figures out how to invert the changes introduced by the commit and appends a new commit with the resulting inverse content. |
||
+ | |} |
||
+ | |||
+ | * [https://www.atlassian.com/git/tutorials/undoing-changes Undoing Commits & Changes] |
||
+ | ** [https://www.atlassian.com/git/tutorials/undoing-changes/git-revert Git Revert] |
||
+ | ** [https://www.atlassian.com/git/tutorials/undoing-changes/git-reset Git Reset] |
||
+ | ** [https://www.atlassian.com/git/tutorials/undoing-changes/git-clean Git Clean] |
||
+ | ** [https://www.atlassian.com/git/tutorials/undoing-changes/git-rm Git RM] |
||
+ | |||
+ | ====Removing untracked files and directories in the working tree==== |
||
<syntaxhighlight lang="bash" enclose="div"> |
<syntaxhighlight lang="bash" enclose="div"> |
||
+ | $ git clean -n // -n: dry run |
||
+ | ... |
||
+ | $ git clean -i // -i: interactive |
||
+ | ... |
||
$ git clean -ndx // -n: dry run, -d: directory also, -x: skip gitignore |
$ git clean -ndx // -n: dry run, -d: directory also, -x: skip gitignore |
||
... |
... |
||
Line 240: | Line 1,159: | ||
* [https://stackoverflow.com/questions/61212/how-to-remove-local-untracked-files-from-the-current-git-working-tree How to remove local (untracked) files from the current Git working tree?] (Sep 14 '08) |
* [https://stackoverflow.com/questions/61212/how-to-remove-local-untracked-files-from-the-current-git-working-tree How to remove local (untracked) files from the current Git working tree?] (Sep 14 '08) |
||
− | === |
+ | ====Undoing tracked files==== |
+ | * To remove uncommitted changes on tracked files in the working tree, use <tt>'git reset --hard'</tt>. |
||
− | @TODO |
||
− | |||
− | ===Creating and pushing tag=== |
||
<syntaxhighlight lang="bash" enclose="div"> |
<syntaxhighlight lang="bash" enclose="div"> |
||
+ | $ git reset --hard // resets the index and working tree. Any changes to tracked files in the working tree since <commit> are discarded. |
||
− | $ git tag -a v1.0 -m "Ready to offer externally" |
||
− | ... |
||
− | $ git push origin v1.0 |
||
− | ... |
||
</syntaxhighlight> |
</syntaxhighlight> |
||
+ | * To unstage a staged file, use <tt>'git reset HEAD <<file>>'</tt>. |
||
− | ===Creating local repository using existing artifacts and pushing it to the remote bare repository=== |
||
<syntaxhighlight lang="bash" enclose="div"> |
<syntaxhighlight lang="bash" enclose="div"> |
||
+ | $ git reset HEAD CONTRIBUTING.md |
||
− | $ git init |
||
− | $ git add . |
||
− | $ git status . |
||
− | $ git commit -m "..." |
||
− | $ git remote add origin https://github.com/.../....git |
||
− | $ git push --set-upstream origin master |
||
− | $ git remote -v |
||
− | $ git push |
||
</syntaxhighlight> |
</syntaxhighlight> |
||
+ | * To unmodify a modified file, use <tt>'git checkout -- <<file>>'</tt>. |
||
− | ===Look around local repository=== |
||
<syntaxhighlight lang="bash" enclose="div"> |
<syntaxhighlight lang="bash" enclose="div"> |
||
+ | $ git checkout -- CONTRIBUTING.md |
||
− | $ git status . // show the working tree status |
||
− | $ git branch -avv // list both remote-tracking branches and local branches. |
||
− | $ git tag -ln // list tags |
||
− | $ git remote -v // list tracking repositories |
||
− | $ git show-ref --head // list references in a local repository |
||
− | $ git log origin/master -3 // lists 3 recent commits for remote branch 'origin/master' |
||
− | $ git ls-files // show information about files in the index and the working tree |
||
− | $ git config -l // list all variables set in config file, along with their values. |
||
</syntaxhighlight> |
</syntaxhighlight> |
||
+ | |||
+ | ====Removing committed changes==== |
||
+ | |||
+ | @TODO |
||
==Companions== |
==Companions== |
||
Line 292: | Line 1,196: | ||
* [https://help.github.com/en/articles/adding-an-existing-project-to-github-using-the-command-line Adding an existing project to GitHub using the command line] |
* [https://help.github.com/en/articles/adding-an-existing-project-to-github-using-the-command-line Adding an existing project to GitHub using the command line] |
||
+ | * [https://github.com/tiimgreen/github-cheat-sheet GitHub Cheat Sheet] |
||
* [https://github.com/github/markup GitHub Markup Support] |
* [https://github.com/github/markup GitHub Markup Support] |
||
** The library that every markup file in a repository goes on before it is rendered on GitHub.com: |
** The library that every markup file in a repository goes on before it is rendered on GitHub.com: |
||
Line 324: | Line 1,229: | ||
* [https://www.endtoend.ai/blog/collapsible-code-blocks/ Collapsible Code Blocks in GitHub Pages] (May 2, 2019) |
* [https://www.endtoend.ai/blog/collapsible-code-blocks/ Collapsible Code Blocks in GitHub Pages] (May 2, 2019) |
||
** <tt><nowiki><details><summary>...</summary>``` ... ```</details></nowiki></tt> |
** <tt><nowiki><details><summary>...</summary>``` ... ```</details></nowiki></tt> |
||
+ | * [https://stackoverflow.com/questions/11938270/how-i-can-move-javadoc-from-master-branch-to-gh-pages-branch-on-github-using-egi How I can move JavaDoc from master branch to gh-pages branch on GitHub using EGit and Eclipse?] (Aug 13 '12) |
||
+ | * [https://pages.github.com/themes/ GitHub Pages supported themes] |
||
* [https://github.com/pages-themes GitHub Pages themes] |
* [https://github.com/pages-themes GitHub Pages themes] |
||
** primer, cayman, hacker, minimal, midnight |
** primer, cayman, hacker, minimal, midnight |
||
Line 352: | Line 1,259: | ||
* Desc : self hosted Git management software |
* Desc : self hosted Git management software |
||
* License : MIT license |
* License : MIT license |
||
+ | |||
+ | * [https://docs.gitlab.com/ee/user/project/protected_branches.html Protected branches] : prevent force push or delete |
||
+ | * [https://docs.gitlab.com/ee/user/markdown.html#table-of-contents GitLab Flavored Markdown (GLFM)] |
||
+ | ** diagrams/flowcharts, front matter, math/LaTex/KaTex, ToC |
||
===Gogs=== |
===Gogs=== |
||
Line 364: | Line 1,275: | ||
===Typical <tt>.gitignore</tt>=== |
===Typical <tt>.gitignore</tt>=== |
||
− | A typical < |
+ | A typical <tt>.gitignore</tt> file contains |
<syntaxhighlight lang="bash" enclose="div"> |
<syntaxhighlight lang="bash" enclose="div"> |
||
+ | # references |
||
+ | # https://git-scm.com/docs/gitignore |
||
+ | # https://github.com/github/gitignore |
||
+ | |||
+ | # source version control related |
||
CVS/ |
CVS/ |
||
.svn/ |
.svn/ |
||
+ | .hg |
||
+ | |||
+ | # IDEs or tools related |
||
+ | # /.vscode/ |
||
/.idea/ |
/.idea/ |
||
+ | .gradle/ |
||
+ | |||
+ | # directories for intermediate or final compiled artifacts |
||
/bin/ |
/bin/ |
||
/target/ |
/target/ |
||
/build/ |
/build/ |
||
/output/ |
/output/ |
||
+ | /out/ |
||
/Debug/ |
/Debug/ |
||
/Release/ |
/Release/ |
||
Line 379: | Line 1,303: | ||
/x64/ |
/x64/ |
||
/obj/ |
/obj/ |
||
+ | /package/ |
||
− | /node_modules/ |
||
+ | |||
+ | # dependencies |
||
+ | /node_modules/* |
||
/pkg/ |
/pkg/ |
||
+ | |||
+ | # generated artifacts |
||
+ | /reports/ |
||
+ | /_site/ |
||
+ | .apt_generated/ |
||
+ | .atp_generated_tests/ |
||
+ | /artifacts/ |
||
+ | /types/ |
||
+ | |||
+ | # runtime outputs |
||
/run/ |
/run/ |
||
/log/ |
/log/ |
||
/logs/ |
/logs/ |
||
/test-output/ |
/test-output/ |
||
+ | *.log |
||
− | /reports/ |
||
− | .apt_generated/ |
||
− | package-lock.json |
||
− | config.gypi |
||
npm-debug.log |
npm-debug.log |
||
+ | |||
− | .npmrc |
||
+ | # backups, caches, or temporary artifacts |
||
+ | .~* |
||
+ | ._* |
||
+ | *.bak |
||
+ | .cache* |
||
+ | .*.swp |
||
+ | *.md.html |
||
+ | # package-lock.json |
||
+ | Gemfile.lock |
||
+ | .sass-cache |
||
+ | __pycache__/ |
||
+ | .pytest_cache/ |
||
packer_cache/ |
packer_cache/ |
||
+ | /.scannerwork |
||
− | /**/*.log |
||
+ | |||
− | /**/*.bak |
||
+ | # misc |
||
− | /**/.~* |
||
+ | config.gypi |
||
− | /**/._* |
||
+ | .npmrc |
||
− | /**/.cache* |
||
+ | .jekyll-metadata |
||
− | /**/.*.swp |
||
+ | .DS_Store |
||
+ | .lock-wscript |
||
+ | .wafpickle-N |
||
+ | /*.tgz |
||
+ | |||
+ | # build outputs of Remix-IDE for smart contracts - https://remix-ide.readthedocs.io/en/latest/contract_metadata.html |
||
+ | contracts/**/artifacts/ |
||
+ | |||
+ | # don't ignore OpenZeppelin contracts |
||
+ | # !/node_modules/@openzeppelin |
||
+ | # /node_modules/@openzeppelin/* |
||
+ | # !/node_modules/@openzeppelin/contracts-3 |
||
+ | # /node_modules/@openzeppelin/contracts-3/build |
||
+ | # /node_modules/@openzeppelin/contracts-3/package.json |
||
+ | # /node_modules/@openzeppelin/contracts-3/**/artifacts |
||
+ | # !/node_modules/@openzeppelin/contracts-4 |
||
+ | # /node_modules/@openzeppelin/contracts-4/build |
||
+ | # /node_modules/@openzeppelin/contracts-4/package.json |
||
+ | # /node_modules/@openzeppelin/contracts-4/**/artifacts |
||
+ | |||
</syntaxhighlight> |
</syntaxhighlight> |
||
Line 403: | Line 1,369: | ||
* [https://git-scm.com/docs/gitignore <code>gitignore</code> documentation] |
* [https://git-scm.com/docs/gitignore <code>gitignore</code> documentation] |
||
* [https://github.com/github/gitignore A collection of useful <code>.gitignore</code> templates] |
* [https://github.com/github/gitignore A collection of useful <code>.gitignore</code> templates] |
||
+ | |||
+ | ===Typical <tt>.gitattribute</tt>=== |
||
+ | |||
+ | * [https://git-scm.com/docs/gitattributes <code>gitattributes</code>] : Defining attributes per path |
||
+ | |||
+ | <syntaxhighlight lang="bash" enclose="div"> |
||
+ | # https://git-scm.com/docs/gitattributes |
||
+ | * -text |
||
+ | |||
+ | *.aj -text |
||
+ | *.cfg -text |
||
+ | *.component -text |
||
+ | *.ftl -text |
||
+ | *.g -text |
||
+ | *.json -text |
||
+ | *.launch -text |
||
+ | *.mediawiki -text |
||
+ | *.MF -text |
||
+ | *.prefs -text |
||
+ | *.q -text |
||
+ | *.script -text |
||
+ | *.sol linguist-language=Solidity |
||
+ | *.tag -text |
||
+ | *.textile -text |
||
+ | *.tokens -text |
||
+ | .classpath -text |
||
+ | .clay -text |
||
+ | .euml2 -text |
||
+ | .fbprefs -text |
||
+ | .jsdtscope -text |
||
+ | .jshintrc -text |
||
+ | .lint4jprefs -text |
||
+ | .pmd -text |
||
+ | .project -text |
||
+ | .springBeans -text |
||
+ | .umlproject -text |
||
+ | |||
+ | # Declare files that will always have CRLF line endings on checkout. |
||
+ | *.sln text eol=crlf |
||
+ | |||
+ | # Denote all files that are truly binary and should not be modified. |
||
+ | *.a binary |
||
+ | *.o binary |
||
+ | *.so binary |
||
+ | *.lib binary |
||
+ | *.com binary |
||
+ | *.exe binary |
||
+ | *.dll binary |
||
+ | *.bin binary |
||
+ | # compressed files |
||
+ | *.zip binary |
||
+ | *.7z binary |
||
+ | # image files |
||
+ | *.png binary |
||
+ | *.jpeg binary |
||
+ | *.jpg binary |
||
+ | *.gif binary |
||
+ | *.bmp binary |
||
+ | *.tif binary |
||
+ | *.tiff binary |
||
+ | # media files |
||
+ | *.mp3 binary |
||
+ | *.mp4 binary |
||
+ | *.avi binary |
||
+ | *.flv binary |
||
+ | *.ico binary |
||
+ | # document files |
||
+ | *.doc binary |
||
+ | *.docx binary |
||
+ | *.xls binary |
||
+ | *.xlsx binary |
||
+ | *.ppt binary |
||
+ | *.pptx binary |
||
+ | *.pdf binary |
||
+ | # misc |
||
+ | *.class binary |
||
+ | *.jar binary |
||
+ | </syntaxhighlight> |
||
</div> |
</div> |
Latest revision as of 01:29, 30 May 2023
Fundamentals
- Git Reference
- Pro Git
- GitHub Bootcamp
- As of Nov. 1st 2012, one important thing is missing. That is sharing the project in Eclipse, after cloning the fork in the server. Maybe it could be a defect of Eclipse, not a miss of the article.
- Git Cheatsheet
- Git Tutorials by Bitbucket
- Git Workflows by Bitbucket
- EGit User Guide
Glossary
Term | Description | Examples | Remarks |
---|---|---|---|
commit (noun)
|
A single point in the Git history | revision, version | |
commit object
|
An object which contains the information about a particular revision, such as parents, committer, author, date and the tree object which corresponds to the top directory of the stored revision. | ||
commit-ish
|
A commit object or an object that can be recursively dereferenced to a commit object | commit object, tag object | |
tree
|
Either a working tree, or a tree object together with the dependent blob and tree objects (i.e. a stored representation of a working tree) | ||
tree object
|
An object containing a list of file names and modes along with refs to the associated blob and/or tree objects | ||
tree-ish
|
A commit-ish, a tree object or a tag object | ||
pathspec
|
Pattern used to limit paths in Git commands | documentation/*.jpg | |
ref
|
A name that begins with refs/ (e.g. refs/heads/master ) that points to an object name or another ref (the latter is called a symbolic ref) |
||
refspec
|
Used by fetch and push to describe the mapping between remote ref and local ref |
push refspec
| |
HEAD
|
The current branch. In more detail: Your working tree is normally derived from the state of the tree referred to by HEAD .
|
detached HEAD , HEAD ≠ head
| |
detached HEAD
|
Git also allows you to check out an arbitrary commit that isn’t necessarily the tip of any particular branch. The HEAD in such a state is called "detached". | ||
upstream branch
|
The default branch that is merged into the branch in question (or the branch in question is rebased onto) |
|
Revision
Type | Format | Description | Examples |
---|---|---|---|
sha1 |
40-byte hexadecimal string | The full SHA-1 object name, or a leading substring that is unique within the repository | dae86e1950b1277e545cee180551750029cfe735 , dae86e
|
refname |
A symbolic ref name | master , heads/master , refs/heads/master , tags/master
| |
<rev>^[<n>] |
the <n>th parent | HEAD^ , v1.5.1^0 , HEAD^^^ , HEAD^^3^2
| |
<rev>~[<n>] |
the commit object that is the <n>th generation ancestor of the named commit object | HEAD~ , HEAD~4 master~3
| |
<rev>:<path> |
the blob or tree at the given path in the tree-ish object named by the part before the colon. | HEAD:README , master:./README
|
- An illustration, by Jon Loeliger
G H I J
\ / \ /
D E F
\ | / \
\ | / |
\|/ |
B C
\ /
\ /
A
A = = A^0
B = A^ = A^1 = A~1
C = = A^2
D = A^^ = A^1^1 = A~2
E = B^2 = A^^2
F = B^3 = A^^3
G = A^^^ = A^1^1^1 = A~3
H = D^2 = B^^2 = A^^^2 = A~2^2
I = F^ = B^3^ = A^^3^
J = F^2 = B^3^2 = A^^3^2
Commands
Category | Command | Description | Remark |
---|---|---|---|
Setup | git config [--get]
|
Get and set repository(local) options | git config --get core.autocrlf git config core.autocrlf false
|
git config --global [--get]
|
Get and set global options | git config --global --get committer.name git config --global init.defaultBranch main
| |
git config --list --show-origin
|
List all variables set in config file, along with their values. | ||
git help --all
|
Prints all the available commands on the standard output | ||
git help -m command
|
Display manual page for the command in the man format | ||
Creating | git clone
|
Clone a repository into a new directory | |
git init
|
Create an empty Git repository or reinitialize an existing one | ||
Snapshotting | git add |
||
git status
|
Show the working tree status | ||
git diff [--] path
|
Show changes you made relative to the index (staging area for the next commit) | working tree (excluding untracked files) vs index | |
git diff commit [--] path
|
Show the changes you have in your working tree relative to the named commit | working tree (excluding untracked files) vs commit | |
git diff --staged commit [--] path
|
the changes you staged for the next commit relative to the named commit (default to HEAD ). |
index vs commit | |
git diff blob1 blob2
|
Show differences between the raw contents of two blob objects | git diff HEAD:docs/GUIDELINES.md HEAD~1:docs/GUIDELINES.md
| |
git diff commit1 commit2 [--] path
|
Show changes between two arbitrary commits | git diff HEAD HEAD^ docs/GUIDELINES.md
| |
git diff --name-only commit1 commit2
|
Show only names of changed files between two arbitrary commits | git diff --name-only v1.2.1 HEAD
| |
git diff --name-status commit1 commit2
|
Show only names and status of changed files between two arbitrary commits | ||
git diff --summary commit1 commit2
|
Output a condensed summary of extended header information such as creations, renames and mode changes. | ||
git diff --stat commit1 commit2
|
|||
git commit |
|||
git reset
|
Reset current HEAD to the specified state | ||
git reset --hard
|
Resets the index and working tree. Any changes to tracked files in the working tree since commit are discarded. | ||
git reset --hard commit
|
Resets the current branch head to commit | Undo commits permanently | |
git reset commit [--] path
|
Reset the index entries for all that match the path to their state at commit | git reset HEAD CONTRIBUTING.md
| |
git restore
|
Restore working tree files or the content in the index | ||
git resotre [--worktree] path
|
Restore working tree files that match the path from the index | ||
git reset --staged path
|
Restore the contents of the index that match the path from HEAD |
||
git rm
|
Remove files from the working tree and from the index | ||
git rm -rf --cached
|
Only remove from the index | Working tree files, whether modified or not, will be left alone | |
Branching | git branch
|
List, create, or delete branches | |
git branch --list
|
List branches. | -l
| |
git branch --all -vvvv
|
List both remote-tracking branches and local branches. | -avvvv
| |
git branch --move oldbranch newbranch
|
Move/rename a branch and the corresponding reflog. | -m
| |
git branch --delete [--force] branch
|
Delete a branch. | -d , -D
| |
git checkout branch
|
To prepare for working on branch, switch to it by updating the index and the files in the working tree, and by pointing HEAD at the branch | ||
git checkout commit [ -- ] pathspec
|
Overwrite both the index and the working tree that match the pathspec with the contents at the commit. | just one file from another branch | |
git checkout -b new-branch [ start-point ] --track remote/branch
|
Create and check out a new branch tracking the specified remote branch from HEAD or the specified start-point if any |
git checkout -b simpler HEAD~3
| |
git checkout --track remote/branch
|
Create and check out a new branch which is tracking and named from the specified remote branch | git checkout -t remote/branch
| |
git push --set-upstream repository src-branch:dst-branch
|
Push src-branch into dst-branch in repository creating a new branch if dst-branch dose not exist yet and then set the src-branch to track the dst-branch | ||
git branch --set-upstream-to=remote/branch′ branch
|
Set up the branch (specified by branch) tracking information so the upstream specified by remote/branch′ is considered it's upstream branch. | git branch --set-upstream-to=origin/bar bar git branch -u origin/bar bar
| |
git branch --set-upstream-to=upstream
|
Set up current branch tracking information so the upstream specified by upstream is considered it's upstream branch. | git branch --set-upstream-to=origin/foo git branch -u origin/foo
| |
git checkout branch [--] pathspec
|
Overwrite the contents of the files that match the pathspec in both the index and the working tree with the contents at the specified branch | ||
git checkout --patch branch [--] pathspec
|
Overwrite the contents of the files that match the pathspec with the interactive interface to show the "diff" output and choose which hunks to use in the result. | --patch , -p
| |
git merge [--ff | --no-ff | --ff-only] commit
|
Join two or more development histories together | ||
git merge --abort
|
Abort the current conflict resolution process, and try to reconstruct the pre-merge state. | ||
git log [branch] -n
|
Show commit logs | git log master -3
| |
git log [-n] --graph [--all]
|
Draw a text-based graphical representation of the commit history on the left hand side of the output. | git log -3 --graph
| |
git tag
|
Create, list, delete or verify a tag object signed with GPG | ||
git tag --list -n2
|
List tags | git tag -l
| |
git tag --list --sort=-taggerdate --format='%(refname:short), %(*objectname), %(contents:subject)'
|
List tags with commit hash and annotation ordered, last tag first | format field names | |
git tag --annotate tagname -m "..."
|
Make(create) an unsigned, annotated tag object | git tag -a
| |
git tag --delete tagname
|
Delete an existing tag with the given name. | git tag -d
| |
Sharing | git fetch
|
Fetch branches and/or tags (collectively, "refs") from one or more other repositories, along with the objects necessary to complete their histories. | git remote add staging; git fetch staging |
git fetch [remote remote-branch] |
|||
git pull [remote remote-branch]
|
Incorporates changes from a remote repository into the current branch | current branch only | |
git push [remote [src-branch[:dst-branch]...]]
|
Push specified branches to the specified remote repository. | branch.*.remote , origin
| |
git push remote tag-name
|
Push a tag to the specified remote repository | git push origin v1.3.0-alpha
| |
git push --all [remote]
|
Push all branches (i.e. refs under refs/heads/ ) into default remote, origin , or specified remote |
||
git push --tags [remote]
|
All refs under refs/tags are pushed |
||
git push --follow-tags
|
Push all the refs that would be pushed without this option, and also push annotated tags in refs/tags that are missing from the remote but are pointing at commit-ish that are reachable from the refs being pushed. |
||
git push --delete tagname
|
Delete a remote tag with the given name. | git push -d
| |
git push --set-upstream
|
For every branch that is up to date or successfully pushed, add upstream (tracking) reference, used by argument-less git-pull and other commands. |
||
git remote -v
|
List tracked repositories | ||
git remote add name url
|
Add a remote | git remote add upstream https://....git
| |
git remote set-url name url
|
Changes URLs for the remote | ||
git remote rename old new
|
Rename a remote | ||
git remote remove
|
Remove a remote | git remote rm
| |
git remote -v show name
|
Gives some information about a remote | git remote -v show origin
| |
git ls-remote
|
List references in a remote repository | git ls-remote origin
| |
Inspection | git show tag
|
Shows the tag message and the referenced objects. | git show v1.0
|
git show rev:path
|
Shows the contents of the file specified by path at rev |
git show HEAD~10:./README.md
| |
Stashing | git stash list
|
List the stash entries that you currently have. | stash@{0} , stash@{1}
|
git stash show stash
|
Show the changes recorded in the stash entry as a diff between the stashed contents and the commit back when the stash entry was first created | ||
git stash push pathspec
|
Save your local modifications to a new stash entry and roll them back to HEAD (in the working tree and in the index) | ||
git stash pop stash
|
Remove a single stashed state from the stash list and apply it on top of the current working tree state | ||
git stash stash
|
Remove a single stash entry from the list of stash entries. | ||
git clear
|
Remove all the stash entries. | ||
Patching | git rebase
|
Reapply commits on top of another base tip | |
git revert
|
Revert some existing commits | Requires your working tree to be clean (no modifications from the HEAD commit) | |
Administration | git clean
|
Remove untracked files from the working tree | |
git archive
|
Create an archive of files from a named tree | git archive -o latest.zip HEAD
| |
Plumbing | git ls-files
|
Show information about files in the index and the working tree | git ls-files | wc -l
|
git show-ref
|
List references in a local repository | ||
Guides | gitignore
|
($HOME/.config/git/ignore, $GIT_DIR/info/exclude, .gitignore )
| |
Misc | git svn
|
Bidirectional operation between a Subversion repository and Git |
Ref
A name that begins with
refs/
(e.g.refs/heads/master
) that points to an object name or another ref.
Type | Format | Example | Remarks |
---|---|---|---|
Local branches | refs/heads/... | refs/heads/2.x, refs/heads/3.x | |
Remote tracking branches | refs/remotes/... | refs/remotes/origin/master, refs/remotes/upstream/master | |
Tags | refs/tags/... | refs/tags/v0.9, refs/tags/v1.5.RELEASE, refs/tags/v2.0.GA |
$ git show-ref
+--- HEAD
|
+--- FETCH_HEAD
|
+--- ORIG_HEAD
|
.git/ ---+--- refs/ ---+--- heads/ ---+--- main
| |
| +--- next
|
+--- tags/ ----+--- v0.9
| |
| +--- v1.0
| |
| +--- v1.1
|
+--- remotes/ ---+--- origin/ --- main
| |
| +--- origin/ --- HEAD
| |
| +--- upstream/ --- main
|
+--- stash/
Reserved Refs
Reserved | Full | Description | Remarks |
---|---|---|---|
master |
refs/heads/master |
local master branch | |
origin/master |
refs/remotes/origin/master |
||
v1.0.1 |
refs/tags/v1.0.1 |
||
HEAD |
currently checkout commit points out the last commit in the current checkout branch. | cat .git/HEAD
| |
FETCH_HEAD |
the result of the last fetch operation | cat .git/FETCH_HEAD
| |
ORIG_HEAD |
the commit that was checked out before a merge or rebase operation was started | cat .git/ORIG_HEAD
|
HEAD
$ cat .git/HEAD
ref: refs/heads/master
$ git checkout test
...
$ cat .git/HEAD
ref: refs/heads/test
- Git Head
- The HEAD points out the last commit in the current checkout branch. It is like a pointer to any reference.
$ git show HEAD
Refspec
Used by
fetch
andpush
to describe the mapping between remote ref and local ref.
Configuration
Variable | Data Type | Description | Default | Remarks |
---|---|---|---|---|
init.defaultBranch
|
string | Allows overriding the default branch name | ||
push.followTags
|
boolean | If set to true enable --follow-tags option by default. | false | --no-follow-tags |
- Common global configuration
$ git config --global init.defaultbranch main
$ git config --global core.autocrlf false
$ git config --global user.name ...
$ git config --global user.email ...
$ git config --global author.name ...
$ git config --global author.email ...
$ git config --global committer.name ...
$ git config --global committer.email ...
Model
File State-chart
Untracked Modified Staged Committed
| | | |
+- add ------------|---------------->| |
| | | |
| +- add ---------->| |
| | | |
| | +- commit ----->|
| | | |
| | | |
| |<----------------|-------- edit -+
| | | |
|<-----------------+-----------------+------ remove -|
| | | |
* Tracked = Modified | Staged | Committed
+-----------+ +---------+ +------------+
| Untracked | ---add---> | Staged | <---add--- | Modified |
|(workspace)| | (index) | |(workspace)|
+-----------+ +---------+ +------------+
| ^
| |
commit edit
| |
| +-----------+ |
+---> | Committed | ---+
+-----------+
Areas
Area | Role | Description | Remarks |
---|---|---|---|
Workspace | Working directory | Consists of files that you are currently working on. | Local checkout |
Index | Staging area, Cache | Where commits are prepared. | |
Stash | A place to hide modifications while you work on something else | ||
Local Repository | |||
Upstream Repository |
Branching
$ git commit -a -m "..."
<< master, HEAD >>
|
+----+ +----+ +----+
| c1 | <----- | c2 | <----- | c3 |
+----+ +----+ +----+
$ git branch iss31 # branch to work on issue 31 - new feature
<< master, HEAD >>
|
+----+ +----+ +----+
| c1 | <----- | c2 | <----- | c3 |
+----+ +----+ +----+
|
<< iss31 >>
$ git checkout iss31
<< master >>
|
+----+ +----+ +----+
| c1 | <----- | c2 | <----- | c3 |
+----+ +----+ +----+
|
<< iss31, HEAD >>
$ # edits or adds some files
$ git commit -a -m ...
<< master >>
|
+----+ +----+ +----+ +----+
| c1 | <----- | c2 | <----- | c3 | <----- | c4 |
+----+ +----+ +----+ +----+
|
<< iss31, HEAD >>
$ # a simple bug is found, create anothter branch for hotfix on 'master'
$ git checkout master
$ git checkout -b hotfix # same with 'git branch hotfix; git checkout hotfix'
<< master, HEAD >>
|
+----+ +----+ +----+ +----+
| c1 | <----- | c2 | <----- | c3 | <----- | c4 |
+----+ +----+ +----+ +----+
|
<< iss31 >>
<< hotfix, HEAD >>
<< master >>
|
+----+ +----+ +----+ +----+
| c1 | <----- | c2 | <----- | c3 | <----- | c4 |
+----+ +----+ +----+ +----+
|
<< iss31 >>
$ # edits some files to fix the bug
$ git commit -a -m ...
<< hotfix, HEAD >>
|
+----+
<< master >> +-- | c5 |
| | +----+
+----+ +----+ +----+ <-----+
| c1 | <----- | c2 | <----- | c3 |
+----+ +----+ +----+ <-----+
| +----+
+-- | c4 |
+----+
|
<< iss31 >>
$ # after successful testing on hotfix, merge 'hotfix' to 'master'. remove 'hotfix' after merge
$ git checkout master
$ git merge hotfix # 'master' fast-forwarded
$ git branch --delete hotfix # --delete == -d
<< hotfix >>
<< master, HEAD >>
|
+----+
+-- | c5 |
| +----+
+----+ +----+ +----+ <-----+
| c1 | <----- | c2 | <----- | c3 |
+----+ +----+ +----+ <-----+
| +----+
+-- | c4 |
+----+
|
<< iss31 >>
<< master, HEAD >>
|
+----+
+-- | c5 |
| +----+
+----+ +----+ +----+ <-----+
| c1 | <----- | c2 | <----- | c3 |
+----+ +----+ +----+ <-----+
| +----+
+-- | c4 |
+----+
|
<< iss31 >>
$ # after hotfix, works on 'iss31' branch with other commits
$ git checkout iss31
<< master >>
|
+----+
+-- | c5 |
| +----+
+----+ +----+ +----+ <-----+
| c1 | <----- | c2 | <----- | c3 |
+----+ +----+ +----+ <-----+
| +----+ +----+ +----+
+-- | c4 | <--- | c6 | <--- | c7 |
+----+ +----+ +----+
|
<< iss31, HEAD >>
$ # when 'iss31' implemented successfully
$ git checkout mater
$ git merge iss31 # if no conflict, simple three-way merge with another new commit
<< master, HEAD >>
|
+----+ <------------------------------- +----+
+-- | c5 | | c8 |
| +----+ +----- +----+
+----+ +----+ +----+ <-----+ | |
| c1 | <----- | c2 | <----- | c3 | | << iss31 >>
+----+ +----+ +----+ <-----+ |
| +----+ +----+ +----+ |
+-- | c4 | <--- | c6 | <--- | c7 | --+
+----+ +----+ +----+
Commands
merge | A---B---C topic
/
D---E---F---G master
|
(master)$ git merge --no-ff topic | A---B---C topic
/ \
D---E---F---G---H master
|
reset --hard | A---B---C topic
/
D---E---F---G---H master
|
(master)$ git reset --hard HEAD~2 | A---B---C topic
/
D---E---F master
|
revert | |||
restore | |||
rebase | A---B---C topic
/
D---E---F---G master
|
$ git rebase master topic | A'--B'--C' topic
/
D---E---F---G master
|
A---B---C topic
/
D---E---A'---F master
|
$ git rebase master topic | B'---C' topic
/
D---E---A'---F master
|
Readings
Topic | Reading | Remark |
---|---|---|
Stashing | Git stash (Bitbucket) |
- What's a “fast-forward” in Git?
- Is there any way to clone a git repository's sub-directory only?
- How to change file premissions in Git on Windows (Nov. 2011)
- Git - Get Current Working Copy Version (Jan 23 '12)
git log -1
- How to get latest git commit hash command (Mar 28 '13)
- Dealing with line endings
- What does tree-ish mean in Git?(Oct 28 '10)
- Ignoring files
- gitignore: Ignore all files in folder hierarchy except one specific filetype (Oct 18 '11)
- How do negated patterns work in .gitignore? (May 12 '10)
/excluded/*
,!/excluded/included
- Git v2.0.0, what changed, and why should you care (2014/05/29)
- Adding an existing project to GitHub using the command line
Revision
- What is a Git Revision Expression? (Aug 1 '09)
- Revision Selection
- gitrevisions
- Git References : refs/heads/, refs/remotes/, refs/tags/ ...
- <refname>
- What is the parent of a git commit? How can there be more than one parent to a git commit? (Jul 7 '16)
Basic Snapshotting
add, status, diff, commit, restore, reset
status
diff
- How to diff the same file between two different commits on the same branch? (Jul 26 '10)
- Git diff between given two tags (Jul 9 '10)
- git: diff between file in local repo and origin (Jan 13 '14)
- $ git fetch; git diff --summary master origin/master
- How to list only the names of files that changed between two commits (Oct 12, 2009)
- git diff --name-only HEAD~10 HEAD~5
reset
command | Description | Remark |
---|---|---|
restore | about restoring files in the working tree from either the index or another commit. | does not update your branch |
reset | updating your branch, moving the tip in order to add or remove commits from the branch. | can also be used to restore the index, overlapping with git restore. |
revert | about making a new commit that reverts the changes made by other commits. |
git revert is used to record some new commits to reverse the effect of some earlier commits (often only a faulty one). If you want to throw away all uncommitted changes in your working directory, you should see git-reset, particularly the --hard option. If you want to extract specific files as they were in another commit, you should see git-restore, specifically the --source option. Take care with these alternatives as both will discard uncommitted changes in your working directory.
- Undo commits permanently
- Delete commit on gitlab (Oct 25, 2016)
git reset --hard CommitId
,git push -f origin master
rm
Branching
branch, checkout, switch, merge, log, tag
- A successful Git branching model (January 05, 2010)
branch
- A branch in Git is simply a lightweight movable pointer to one of these commits.
- Every time you commit, the master branch pointer moves forward automatically.
- HEAD is a pointer to the local branch you’re currently on.
Term | Description | Remark |
---|---|---|
Remote-tracking Branch | ||
Upstream Branch |
- What is the difference between origin and upstream on GitHub? (Feb 13 '12)
- Definition of “downstream” and “upstream”(Apr 29 '10)
- Removing a remote
- How do you create a remote Git branch? (Oct 5 '09)
git push <remote-name> <local-branch-name>:<remote-branch-name>
- Make an existing Git branch track a remote branch?(Feb 6, 2009)
git branch -u upstream/foo foo
orgit branch --set-upstream-to=upstream/foo foo
- How To Rename a Local and Remote Git Branch (Feb 18, 2020)
- git branch -m name, git push origin --delete name
- How to list all the files in a commit? (Jan 8 '09)
- git show --name-only -1, git log --name-only -1
checkout
- How to checkout remote git tag (Mar 14 '16)
git checkout v1.0.0, git checkout tags/v1.0.0
- How to get back to most recent version in Git? (Aug 24 '10)
git checkout master
- How to get just one file from another branch? (asked Mar 2 2010)
git checkout experiment -- app.js
- Git tip: How to "merge" specific files from another branch (February 25, 2009)
git checkout source_branch paths
- How do I merge changes to a single file, rather than merging commits? ( May 28, 2012)
- How to Check out a Remote Git Branch [Step-by-Step] (30 March 2021)
- A Git repository itself may have multiple remotes, but a branch can only reference a single remote.
- The fetch command will connect to the remote repository and retrieve a list of all available branches.
git checkout RemoteBranch
- git checkout a Remote Branch
- In order to see this newly published branch, you will have to perform a simple "git fetch" for the remote.
$ git checkout --track origin/newsletter
merge
- How do I cancel a git merge?
git reset --hard HEAD
orgit merge --abort
tag
- How to list all tags along with the full message in git? (Mar 18 '11)
git tag -l -n9
- How to tell which commit a tag points to in Git? (Dec 7, 2009)
- $ git show-ref --tags
- $ git show tagname
- How to push a tag to a remote repository using Git? (Mar 4 '11)
git push origin --tags
- How do you push a tag to a remote repository using Git? (Mar 4 '11)
- git push origin <tag_name>
- How To Delete Local and Remote Tags on Git
- $ git push --delete origin tag-name
Sharing
fetch, pull, push, remote
- Find out which remote branch a local branch is tracking (Oct 5 '08)
git branch -vv
,git status
- Pushing to a remote
- By default, and without additional parameters,
git push
sends all matching branches that have the same names as remote branches.
- By default, and without additional parameters,
- Why do I have to "git push --set-upstream origin <branch>"? (Jun 12, 2016)
git push -u origin solaris
- How to Rename the master branch to main in Git
- How does origin/HEAD get set? (Jan 12, 2012)
- origin's HEAD will only change if you or someone else actually changes it in the remote repository
Workflow
- A successful Git branching model (January 05, 2010)
Hooks
Tools
Misc
- Changing a commit message : git commit --amend
- Add line break to 'git commit -m' from the command line (Feb 21 '11)
- Using Git Show to View Contents of Files (DECEMBER 14, 2019)
git show <version>:<file>
Subtree
- About Git subtree merges
- to manage multiple projects within a single repository
- Mastering Git subtrees
Typical Usage
Configuration
List all configuration
$ git config --list --show-scope --show-origin
Snapshotting
Add, commit and push
$ git status . // identifies added, modified or untracked items under current local directory
$ git add . // updates index
$ git status . // confirms the changes to be committed
$ git commit -m "message ..." // commits changes into local repository
$ git status . // confirms all changes are committed
$ git push // pushes changes in local repository onto the remote repository
$ git log --name-only -1 // lists files in the last commit
When the HEAD of 'origin/master' has changed since the last sync, '$ git push' would fail with messages including fast-forwards. Then,
$ git pull --rebase
...
may need manual merge.
...
$ git push
Creating local repository using existing artifacts
... and pushing it to the remote bare repository
$ git init
$ git add .
$ git status .
$ git commit -m "..."
$ git remote add origin https://github.com/.../....git
$ git push --set-upstream origin master
$ git remote -v
Look around local repository
$ git status . // show the working tree status
$ git branch --all -vvvv // list both remote-tracking branches and local branches.
$ git tag -ln // list tags
$ git remote -v // list tracking repositories
$ git show-ref // list references in a local repository
$ git log origin/master -3 // lists 3 recent commits for remote branch 'origin/master'
$ git ls-files // show information about files in the index and the working tree
$ git config -l // list all variables set in config file, along with their values.
Tracking changes
$ git log master -3 // lists 3 recent commits for master branch
$ git log v2.0.2 -3 // lists 3 last commits before the tag of 'v2.0.2'
$ git log origin/master -1 // lists last commit of remote branch 'origin/master'
$ git log upstream/master -1 // lists last commit of remote branch 'upstream/master'
$ git log --name-only -1 // lists files in the last commit.
Branching
Working with branches or tags
$ git tag -ln // lists tags
$ git tag -a v2.0.2 -m "before new branch" // creates a new annotated tag(v2.0.2)
$ git tag origin v2.0.2 // push a tag to a remote
$ git push origin --tags // pushes all local tags to remote 'origin'
$ git branch // lists branches
$ git branch -a // lists both local and remote-tracking branches
$ git branch -avv // lists all branches showing hash and upstream branch if any
$ git branch 1.1 // creates a new branch(1.1) from the master (branch)
$ git branch 2.0.2-ext v2.0.2 // creates a new branch(2.0.2-ext) from a tag(v2.0.2)
$ git push origin advanced:advanced // creates remote branch 'origin/advanced' from local branch 'advanced'
$ git push --set-upstream origin advanced // sets upstream(tracking) reference for current branch to
$ git checkout release-1.1 // updates working tree to release-1.1
$ git checkout -b gh-pages origin/gh-pages // copies remote branch to local repository
Creating and pushing tag
$ git tag -a v1.0 -m "Ready to offer externally"
...
$ git push origin v1.0
...
Sharing
Managing remote repositories
$ git remote -v // lists tracking repositories
$ git remote add upstream https://github.com/jpmorganchase/quorum.git // add a new remote repository to track
$ git branch -r // lists branches in tracking repositories
The default branch has been renamed!
master is now named main
If you have a local clone, you can update it by running the following commands.
git branch -m master main
git fetch origin
git branch -u origin/main main
git remote set-head origin -a
Undoing
Use-case | Solution | Example | Remarks |
---|---|---|---|
Removing untracked files and directories | git clean -dx |
||
Removing uncommitted changes on all the tracked files | git reset --hard |
||
Undo commits permanently | git reset --hard commit
|
git reset --hard HEAD |
|
Removing uncommitted changes on a single or selected tracked files | git checkout commit [ -- ] pathspec
|
Overwrite both the index and the working tree that match the pathspec with the contents at the commit. | |
Reverting committed changes | git revert commit |
git revert HEAD
|
revert : go back to a previous state. Instead of removing the commit from the project history, it figures out how to invert the changes introduced by the commit and appends a new commit with the resulting inverse content. |
Removing untracked files and directories in the working tree
$ git clean -n // -n: dry run
...
$ git clean -i // -i: interactive
...
$ git clean -ndx // -n: dry run, -d: directory also, -x: skip gitignore
...
$ git clean -ffdx // -ff: force including files manged by different Git repository
...
For more, refer
- how to remove untracked files in Git? (Nov 20 '11)
- How to remove local (untracked) files from the current Git working tree? (Sep 14 '08)
Undoing tracked files
- To remove uncommitted changes on tracked files in the working tree, use 'git reset --hard'.
$ git reset --hard // resets the index and working tree. Any changes to tracked files in the working tree since <commit> are discarded.
- To unstage a staged file, use 'git reset HEAD <<file>>'.
$ git reset HEAD CONTRIBUTING.md
- To unmodify a modified file, use 'git checkout -- <<file>>'.
$ git checkout -- CONTRIBUTING.md
Removing committed changes
@TODO
Companions
GitHub
- Fork A Repo
- Syncing a fork
- Configuring a remote for a fork
- Configuring Git Large File Storage : Git LFS
- Adding an existing project to GitHub using the command line
- GitHub Cheat Sheet
- GitHub Markup Support
- The library that every markup file in a repository goes on before it is rendered on GitHub.com:
Markup | Extension | Library |
---|---|---|
Markdown | .markdown, .md | https://github.com/gjtorikian/commonmarker |
MediaWiki | .mediawiki, .wiki | https://github.com/nricciar/wikicloth |
Textile | .textile | https://github.com/jgarber/redcloth |
AsciiDoc | .asciidoc, .adoc | http://asciidoctor.org/ |
reStructuredText | .rst |
GitHub Pages
- Get Started With GitHub Pages (Plus Bonus Jekyll)(18 December 2013)
- A blog site with Jekyll, Github Pages Eclipse Che and Codenvy
- Using Jekyll as a static site generator with GitHub Pages
- Collapsible Code Blocks in GitHub Pages (May 2, 2019)
- <details><summary>...</summary>``` ... ```</details>
- How I can move JavaDoc from master branch to gh-pages branch on GitHub using EGit and Eclipse? (Aug 13 '12)
- GitHub Pages supported themes
- GitHub Pages themes
- primer, cayman, hacker, minimal, midnight
EGit
- http://www.eclipse.org/egit/
- Desc : an Eclipse Team provider for the Git version control system.
- License
- Readings
- EGit User Guide
- Git For Eclipse Users
- EGit Getting Started
- EGit/GitHub/User Guide : explains how to use EGit Mylyn GitHub connector.
- EGit Compare shows all lines as changed (Dec 30 '13)
- EGit doesn't support
.gitattributes
file.
- EGit doesn't support
Gitorious
- Desc : Git hosting and collaboration software that you can install yourself
- License : GNU Affero General Public License
GitLab
- https://github.com/gitlabhq/gitlabhq
- Desc : self hosted Git management software
- License : MIT license
- Protected branches : prevent force push or delete
- GitLab Flavored Markdown (GLFM)
- diagrams/flowcharts, front matter, math/LaTex/KaTex, ToC
Gogs
- https://gogs.io/
- Desc. : a painless self-hosted Git service
- License : MIT License
- Sources : https://github.com/gogs/gogs
Tips and Tricks
Typical .gitignore
A typical .gitignore file contains
# references
# https://git-scm.com/docs/gitignore
# https://github.com/github/gitignore
# source version control related
CVS/
.svn/
.hg
# IDEs or tools related
# /.vscode/
/.idea/
.gradle/
# directories for intermediate or final compiled artifacts
/bin/
/target/
/build/
/output/
/out/
/Debug/
/Release/
/x86/
/x64/
/obj/
/package/
# dependencies
/node_modules/*
/pkg/
# generated artifacts
/reports/
/_site/
.apt_generated/
.atp_generated_tests/
/artifacts/
/types/
# runtime outputs
/run/
/log/
/logs/
/test-output/
*.log
npm-debug.log
# backups, caches, or temporary artifacts
.~*
._*
*.bak
.cache*
.*.swp
*.md.html
# package-lock.json
Gemfile.lock
.sass-cache
__pycache__/
.pytest_cache/
packer_cache/
/.scannerwork
# misc
config.gypi
.npmrc
.jekyll-metadata
.DS_Store
.lock-wscript
.wafpickle-N
/*.tgz
# build outputs of Remix-IDE for smart contracts - https://remix-ide.readthedocs.io/en/latest/contract_metadata.html
contracts/**/artifacts/
# don't ignore OpenZeppelin contracts
# !/node_modules/@openzeppelin
# /node_modules/@openzeppelin/*
# !/node_modules/@openzeppelin/contracts-3
# /node_modules/@openzeppelin/contracts-3/build
# /node_modules/@openzeppelin/contracts-3/package.json
# /node_modules/@openzeppelin/contracts-3/**/artifacts
# !/node_modules/@openzeppelin/contracts-4
# /node_modules/@openzeppelin/contracts-4/build
# /node_modules/@openzeppelin/contracts-4/package.json
# /node_modules/@openzeppelin/contracts-4/**/artifacts
For more, refer
Typical .gitattribute
gitattributes
: Defining attributes per path
# https://git-scm.com/docs/gitattributes
* -text
*.aj -text
*.cfg -text
*.component -text
*.ftl -text
*.g -text
*.json -text
*.launch -text
*.mediawiki -text
*.MF -text
*.prefs -text
*.q -text
*.script -text
*.sol linguist-language=Solidity
*.tag -text
*.textile -text
*.tokens -text
.classpath -text
.clay -text
.euml2 -text
.fbprefs -text
.jsdtscope -text
.jshintrc -text
.lint4jprefs -text
.pmd -text
.project -text
.springBeans -text
.umlproject -text
# Declare files that will always have CRLF line endings on checkout.
*.sln text eol=crlf
# Denote all files that are truly binary and should not be modified.
*.a binary
*.o binary
*.so binary
*.lib binary
*.com binary
*.exe binary
*.dll binary
*.bin binary
# compressed files
*.zip binary
*.7z binary
# image files
*.png binary
*.jpeg binary
*.jpg binary
*.gif binary
*.bmp binary
*.tif binary
*.tiff binary
# media files
*.mp3 binary
*.mp4 binary
*.avi binary
*.flv binary
*.ico binary
# document files
*.doc binary
*.docx binary
*.xls binary
*.xlsx binary
*.ppt binary
*.pptx binary
*.pdf binary
# misc
*.class binary
*.jar binary