Difference between revisions of "Git"
From Christoph's Personal Wiki
(→External links) |
(→Miscellaneous) |
||
(13 intermediate revisions by the same user not shown) | |||
Line 5: | Line 5: | ||
==Examples== | ==Examples== | ||
===Basic=== | ===Basic=== | ||
− | *Quick help | + | * Quick help: |
− | git help # returns most common commands | + | $ git help # returns most common commands |
− | git help -a # get a list of all installed git commands | + | $ git help -a # get a list of all installed git commands |
− | man git-add # man page on the 'add' command | + | $ man git-add # man page on the 'add' command |
− | *Start a new git repository: | + | |
− | mkdir my_new_project && cd my_new_project | + | * Start a new git repository: |
− | git init | + | $ mkdir my_new_project && cd my_new_project |
+ | $ git init | ||
# create some new files, then: | # create some new files, then: | ||
− | git add . | + | $ git add . |
− | git commit | + | $ git commit |
− | *See what has changed since last commit: | + | #~OR~ |
− | git diff | + | $ git commit -am 'initial commit message' |
− | *A more concise way to view what has changed and what needs to be done | + | |
− | git status | + | * See what has changed since last commit: |
+ | $ git diff | ||
+ | |||
+ | * A more concise way to view what has changed and what needs to be done: | ||
+ | $ git status | ||
+ | |||
+ | * Clone a specific remote branch: | ||
+ | $ git clone --single-branch --branch <branchname> <remote-repo> | ||
+ | |||
+ | ===Miscellaneous=== | ||
+ | |||
+ | * View current git user: | ||
+ | $ git config user.email | ||
+ | |||
+ | * Change to a different git user: | ||
+ | $ git config --global user.email "someone@somewhere.com" | ||
+ | |||
+ | * Check <code>git log</code> for a specific function in a specific (e.g., Python) file: | ||
+ | <pre> | ||
+ | # Syntax: | ||
+ | $ git log -L :<funcname>:<file> | ||
+ | |||
+ | # Example: | ||
+ | $ git log -L :load_json:compare_rke_state_files.py | ||
+ | commit b5ac4b65f9554a32fbec64435171c07a20a52de8 | ||
+ | Author: Christoph Champ <someone@somewhere.com> | ||
+ | Date: Sat Jun 15 18:47:12 2019 -0700 | ||
+ | initial commit of compare_rke_state_files.py | ||
+ | diff --git a/ansible/compare_rke_state_files.py b/ansible/compare_rke_state_files.py | ||
+ | --- /dev/null | ||
+ | +++ b/ansible/compare_rke_state_files.py | ||
+ | @@ -0,0 +8,6 @@ | ||
+ | +def load_json(filename): | ||
+ | + with open(filename) as json_file: | ||
+ | + data = json.load(json_file) | ||
+ | + return data | ||
+ | </pre> | ||
===git-svn=== | ===git-svn=== | ||
− | The following three commands will import a remote [[svn]] repository into a local git repository | + | * The following three commands will import a remote [[svn]] repository into a local git repository: |
− | mkdir pymmlib && cd pymmlib | + | $ mkdir pymmlib && cd pymmlib |
− | git svn init -t tags -b branches -T trunk <nowiki>https://pymmlib.svn.sourceforge.net/svnroot/pymmlib</nowiki> | + | $ git svn init -t tags -b branches -T trunk <nowiki>https://pymmlib.svn.sourceforge.net/svnroot/pymmlib</nowiki> |
− | git svn fetch | + | $ git svn fetch |
+ | |||
+ | ==Gitconfig== | ||
+ | |||
+ | * Example: | ||
+ | <pre> | ||
+ | $ cat ~/.gitconfig | ||
+ | [user] | ||
+ | name = Christoph Champ | ||
+ | email = someone@somewhere.com | ||
+ | [push] | ||
+ | default = simple | ||
+ | [alias] | ||
+ | lg1 = log --graph --abbrev-commit --decorate --date=relative --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(bold yellow)%d%C(reset)' --all | ||
+ | lg2 = log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold cyan)%aD%C(reset) %C(bold green)(%ar)%C(reset)%C(bold yellow)%d%C(reset)%n'' %C(white)%s%C(reset) %C(dim white)- %an%C(reset)' --all | ||
+ | lg3 = log --graph --abbrev-commit --decorate --all \ | ||
+ | --format=format:'%C(bold blue)%h%C(reset) - %C(bold cyan)%aD%C(dim white) - %an%C(reset) %C(bold green)(%ar)%C(reset)%C(bold yellow)%d%C(reset)%n %C(white)%s%C(reset)' | ||
+ | lg = !"git lg1" | ||
+ | [url "git@github.com:"] | ||
+ | insteadOf = https://github.com/ | ||
+ | </pre> | ||
==See also== | ==See also== | ||
*[[svn]] | *[[svn]] | ||
− | |||
==External links== | ==External links== | ||
− | *[http://git. | + | *[http://git-scm.com/ Official website] |
*[http://www.kernel.org/pub/software/scm/git/docs/user-manual.html Git User's Manual], also distributed with Git in Documentation/user-manual.txt | *[http://www.kernel.org/pub/software/scm/git/docs/user-manual.html Git User's Manual], also distributed with Git in Documentation/user-manual.txt | ||
− | *[http://www. | + | *[http://maryrosecook.com/blog/post/git-in-six-hundred-words Git in six hundred words] |
+ | *[http://maryrosecook.com/blog/post/git-from-the-inside-out Git from the inside out] | ||
+ | *[http://www.gelato.unsw.edu.au/archives/git/0512/13748.html git for the confused] — extremely in-depth manual/tutorial | ||
+ | *[https://git.kernel.org/cgit/ Kernel.org git repositories] | ||
*[http://linux.yyz.us/git-howto.html Kernel Hackers' Guide to git] | *[http://linux.yyz.us/git-howto.html Kernel Hackers' Guide to git] | ||
*[http://www.linux-mips.org/wiki/Git Git] and [http://www.linux-mips.org/wiki/WhatIsGit WhatIsGit] at [http://www.linux-mips.org LinuxMIPS] wiki | *[http://www.linux-mips.org/wiki/Git Git] and [http://www.linux-mips.org/wiki/WhatIsGit WhatIsGit] at [http://www.linux-mips.org LinuxMIPS] wiki | ||
− | *[http:// | + | *"[http://2ndscale.com/rtomayko/2008/the-thing-about-git The Thing About Git]" |
− | + | *"[http://mikegerwitz.com/papers/git-horror-story A Git Horror Story: Repository Integrity With Signed Commits]", by Mike Gerwitz | |
− | + | ||
− | *[http:// | + | |
− | + | ||
[[Category:Linux Command Line Tools]] | [[Category:Linux Command Line Tools]] | ||
+ | [[Category:DevOps]] |
Latest revision as of 00:38, 19 February 2021
Git is a distributed revision control / software configuration management project created by Linus Torvalds, initially for the Linux kernel development.
Git is by far my favourite revision control system. I not only use it for software management, I also use it as my backup system for any of my text files.
Examples
Basic
- Quick help:
$ git help # returns most common commands $ git help -a # get a list of all installed git commands $ man git-add # man page on the 'add' command
- Start a new git repository:
$ mkdir my_new_project && cd my_new_project $ git init # create some new files, then: $ git add . $ git commit #~OR~ $ git commit -am 'initial commit message'
- See what has changed since last commit:
$ git diff
- A more concise way to view what has changed and what needs to be done:
$ git status
- Clone a specific remote branch:
$ git clone --single-branch --branch <branchname> <remote-repo>
Miscellaneous
- View current git user:
$ git config user.email
- Change to a different git user:
$ git config --global user.email "someone@somewhere.com"
- Check
git log
for a specific function in a specific (e.g., Python) file:
# Syntax: $ git log -L :<funcname>:<file> # Example: $ git log -L :load_json:compare_rke_state_files.py commit b5ac4b65f9554a32fbec64435171c07a20a52de8 Author: Christoph Champ <someone@somewhere.com> Date: Sat Jun 15 18:47:12 2019 -0700 initial commit of compare_rke_state_files.py diff --git a/ansible/compare_rke_state_files.py b/ansible/compare_rke_state_files.py --- /dev/null +++ b/ansible/compare_rke_state_files.py @@ -0,0 +8,6 @@ +def load_json(filename): + with open(filename) as json_file: + data = json.load(json_file) + return data
git-svn
- The following three commands will import a remote svn repository into a local git repository:
$ mkdir pymmlib && cd pymmlib $ git svn init -t tags -b branches -T trunk https://pymmlib.svn.sourceforge.net/svnroot/pymmlib $ git svn fetch
Gitconfig
- Example:
$ cat ~/.gitconfig [user] name = Christoph Champ email = someone@somewhere.com [push] default = simple [alias] lg1 = log --graph --abbrev-commit --decorate --date=relative --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(bold yellow)%d%C(reset)' --all lg2 = log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold cyan)%aD%C(reset) %C(bold green)(%ar)%C(reset)%C(bold yellow)%d%C(reset)%n'' %C(white)%s%C(reset) %C(dim white)- %an%C(reset)' --all lg3 = log --graph --abbrev-commit --decorate --all \ --format=format:'%C(bold blue)%h%C(reset) - %C(bold cyan)%aD%C(dim white) - %an%C(reset) %C(bold green)(%ar)%C(reset)%C(bold yellow)%d%C(reset)%n %C(white)%s%C(reset)' lg = !"git lg1" [url "git@github.com:"] insteadOf = https://github.com/
See also
External links
- Official website
- Git User's Manual, also distributed with Git in Documentation/user-manual.txt
- Git in six hundred words
- Git from the inside out
- git for the confused — extremely in-depth manual/tutorial
- Kernel.org git repositories
- Kernel Hackers' Guide to git
- Git and WhatIsGit at LinuxMIPS wiki
- "The Thing About Git"
- "A Git Horror Story: Repository Integrity With Signed Commits", by Mike Gerwitz