Git: Difference between revisions

From Han Wiki
Jump to navigation Jump to search
dump from oldwiki
Line 1: Line 1:
=== signing work ===
= signing work =


This is an example of GPG key.
This is an example of GPG key.
Line 6: Line 6:
git config --global user.signingkey 0A46826A
git config --global user.signingkey 0A46826A
</source>
</source>
= Commands =
== Add a local branch that tracks a remote branch ==
<syntaxhighlight lang="bash">
$ git branch --track greet origin/greet
$ git branch -a
$ git merge origin/master
</syntaxhighlight>
== Pulling changes from a remote ==
<syntaxhighlight lang="bash">
$ git fetch
$ git merge origin/master
</syntaxhighlight>
is equivalent to:
<syntaxhighlight lang="bash">
$ git pull
</syntaxhighlight>
== Rebase a branch ==
<syntaxhighlight lang="bash">
$ git checkout cbranch
Switched to branch 'cbranch'
$ git rebase master
First, rewinding head to replay your work on top of it...
Applying: added Greeter class
Applying: hello uses Greeter
Applying: updated Rakefile
$
</syntaxhighlight>
== Merge a branch ==
<syntaxhighlight lang="bash">
$ git checkout autonotif
Switched to branch 'autonotif'
$ git merge <branchname>
Merge made by the 'recursive' strategy.
foobarrecords_savenew.hns | 1 +
1 file changed, 1 insertion(+)
create mode 100644 foobarrecords_savenew.hns
</syntaxhighlight>
Merges <branchname> onto autonotif branch
== Remove a tag ==
<syntaxhighlight lang="bash">
$ git tag -d <tagname>
</syntaxhighlight>
== Undo last commit ==
This undo is recorded as a part of the git log.
<syntaxhighlight lang="bash">
$ git revert HEAD
</syntaxhighlight>
== Reset the branch to a specific point in the past ==
<syntaxhighlight lang="bash">
$ git reset --hard <hash>
</syntaxhighlight>
--hard parameter also updates the working directory. Reset shouldn't be used in a group project on a remote repository because of its potential for confusion.
== Ignore files ==
;Temporary ignore changes to a file
<syntaxhighlight lang="bash">
$ git update-index --assume-unchanged <filename>
</syntaxhighlight>
;Back to tracking changes to the file
<syntaxhighlight lang="bash">
$ git update-index --no-assume-unchanged <filename>
</syntaxhighlight>
== Ignore file modes ==
This is useful when working with multiple file systems.
<source lang="bash">
$ git config core.filemode false
</source>
= Useful git aliases =
This is a snapshot of my ~/.gitconfig
<syntaxhighlight lang="ini">
[user]
        name = Michael Han
        email = mhan@pfg.fjfj.com
[core]
        editor = vim
        autocrlf = input
        safecrlf = true
[color]
        ui = always
[alias]
        co = checkout
        ci = commit
        st = status
        br = branch
        df = difftool
        hist = log --pretty=format:\"%C(yellow)%h %C(green)%ad %Creset| %s%C(red)%d %C(blue)[%an]\" --graph --date=short
        histall = log --pretty=format:\"%C(yellow)%h %C(green)%ad %Creset| %s%C(red)%d %C(blue)[%an]\" --graph --date=short --all
        hist10 = !git log --pretty=format:\"%C(yellow)%h %C(green)%ad %Creset| %s%C(red)%d %C(blue)[%an]\" --graph --date=short | head -n 10
        hist10all = !git log --pretty=format:\"%C(yellow)%h %C(green)%ad %Creset| %s%C(red)%d %C(blue)[%an]\" --graph --date=short --all | head -n 10
        type = cat-file -t
        dump = cat-file -p
        ignore = update-index --assume-unchanged
        track = update-index --no-assume-unchanged
        listignored = !git ls-files -v | grep -s ^'h ' | cut -b 1-2 --complement
[diff]
        tool = vimdiff
[difftool]
        prompt = false
[merge]
        defaultToUpstream = true
</syntaxhighlight>
= Links =
;http://qugstart.com/blog/ruby-and-rails/create-a-new-git-remote-repository-from-some-local-files-or-local-git-repository/
;http://gitimmersion.com/
;http://kris.me.uk/2010/09/30/git-repository-server-gitolite.html
;http://www.lucidlynx.com/how-to-install-gitweb-in-ubuntu/
;http://mustalikachwala.blogspot.com/2012/07/ubuntu-1204-installing-gitolite-and.html
;http://ben.kulbertis.org/2011/10/synchronizing-a-mysql-database-with-git-and-git-hooks/
;http://viget.com/extend/backup-your-database-in-git
;http://longair.net/blog/2009/04/16/git-fetch-and-merge/
:a warning against pull
'http://git-scm.com/book/en/Git-Branching-Basic-Branching-and-Merging

Revision as of 19:57, 29 June 2016

signing work

This is an example of GPG key.

git config --global user.signingkey 0A46826A

Commands

Add a local branch that tracks a remote branch

$ git branch --track greet origin/greet
$ git branch -a
$ git merge origin/master

Pulling changes from a remote

$ git fetch
$ git merge origin/master

is equivalent to:

$ git pull

Rebase a branch

$ git checkout cbranch
Switched to branch 'cbranch'

$ git rebase master
First, rewinding head to replay your work on top of it...
Applying: added Greeter class
Applying: hello uses Greeter
Applying: updated Rakefile

$

Merge a branch

$ git checkout autonotif
Switched to branch 'autonotif'

$ git merge <branchname>
Merge made by the 'recursive' strategy.
 foobarrecords_savenew.hns | 1 +
 1 file changed, 1 insertion(+)
 create mode 100644 foobarrecords_savenew.hns

Merges <branchname> onto autonotif branch

Remove a tag

$ git tag -d <tagname>

Undo last commit

This undo is recorded as a part of the git log.

$ git revert HEAD

Reset the branch to a specific point in the past

$ git reset --hard <hash>

--hard parameter also updates the working directory. Reset shouldn't be used in a group project on a remote repository because of its potential for confusion.

Ignore files

Temporary ignore changes to a file
$ git update-index --assume-unchanged <filename>
Back to tracking changes to the file
$ git update-index --no-assume-unchanged <filename>

Ignore file modes

This is useful when working with multiple file systems.

$ git config core.filemode false

Useful git aliases

This is a snapshot of my ~/.gitconfig

[user]
        name = Michael Han
        email = mhan@pfg.fjfj.com
[core]
        editor = vim
        autocrlf = input
        safecrlf = true
[color]
        ui = always
[alias]
        co = checkout
        ci = commit
        st = status
        br = branch
        df = difftool
        hist = log --pretty=format:\"%C(yellow)%h %C(green)%ad %Creset| %s%C(red)%d %C(blue)[%an]\" --graph --date=short
        histall = log --pretty=format:\"%C(yellow)%h %C(green)%ad %Creset| %s%C(red)%d %C(blue)[%an]\" --graph --date=short --all
        hist10 = !git log --pretty=format:\"%C(yellow)%h %C(green)%ad %Creset| %s%C(red)%d %C(blue)[%an]\" --graph --date=short | head -n 10
        hist10all = !git log --pretty=format:\"%C(yellow)%h %C(green)%ad %Creset| %s%C(red)%d %C(blue)[%an]\" --graph --date=short --all | head -n 10
        type = cat-file -t
        dump = cat-file -p
        ignore = update-index --assume-unchanged
        track = update-index --no-assume-unchanged
        listignored = !git ls-files -v | grep -s ^'h ' | cut -b 1-2 --complement
[diff]
        tool = vimdiff
[difftool]
        prompt = false
[merge]
        defaultToUpstream = true

Links

http://qugstart.com/blog/ruby-and-rails/create-a-new-git-remote-repository-from-some-local-files-or-local-git-repository/
http://gitimmersion.com/
http://kris.me.uk/2010/09/30/git-repository-server-gitolite.html
http://www.lucidlynx.com/how-to-install-gitweb-in-ubuntu/
http://mustalikachwala.blogspot.com/2012/07/ubuntu-1204-installing-gitolite-and.html
http://ben.kulbertis.org/2011/10/synchronizing-a-mysql-database-with-git-and-git-hooks/
http://viget.com/extend/backup-your-database-in-git
http://longair.net/blog/2009/04/16/git-fetch-and-merge/
a warning against pull

'http://git-scm.com/book/en/Git-Branching-Basic-Branching-and-Merging