PMT: git memo
出典: Scratchpad Wiki
目次 |
[編集] initialize
Define who you are
$ git config --global user.name "My Name" $ git config --global user.email My.name@some.company
In your working directory, we must type first
$ git init
It will make .git/ directory.
[編集] make history
If you include all the files in your directory,
$ git add . $ git commit
git commit will open editor. vi editor in default. Use EDITOR environment variables to change it. See also man git-commit. You must write some comments and exit it. You make your first repository. You can check your version by
$ git log
commit 6ff09b732e4d9913a2eb9bd72c57c104cdb1599c
Author: My Name
Date: Thu Apr 2 18:02:30 2009 +0900
lm-7.0betaK001 09.03.30
git controls versions not by version numbers but by hex numbers, 6ff0... Here
lm-7.0betaK001 09.03.30
is my comment.
[編集] git add
$ git add .
includes all the files and directories in the ./ directory. You can specify files and directories you want to include like
git add Makefile fp gwd
Here I change Makefile. After that
$ git add Makefile $ git commit
You must '$ git add' filenames you changed. Or you can do
$ git commit -a
which automatically does '$ git add' and '$ git commit'. You made your second repository. We can check it by
$ git log
commit 72979cde141b81c7a6058a135f09c7ee1b57d2dc
Author: My Name
Date: Thu Apr 2 18:03:54 2009 +0900
MODDIR -> $(moddir)
commit 6ff09b732e4d9913a2eb9bd72c57c104cdb1599c
Author: My Name
Date: Thu Apr 2 18:02:30 2009 +0900
lm-7.0betaK001 09.03.30
Here MODDIR -> $(moddir) and lm-7.0betaK001 09.03.30 are my comments. You have two commits. Let's move back to the commit 6ff09b732e4d9913a2eb9bd72c57c104cdb1599c.
$ git checkout 6ff09b732e4d9913a2eb9bd72c57c104cdb1599c Note: moving to "6ff09b732e4d9913a2eb9bd72c57c104cdb1599c" which isn't a local branch If you want to create a new branch from this checkout, you may do so (now or later) by using -b with the checkout command again. Example: git checkout -b HEAD is now at 6ff09b7... lm-7.0betaK001 09.03.30
You see warning messages, Note:..., but the operation is completed.
- I used all the numbers, but 6ff is enough to distinguish them. i.e.
- '$ git checkout 6ff'
Please confirm that this Makefile is the original one. You can't see the newest one with git.
$ git log
commit 6ff09b732e4d9913a2eb9bd72c57c104cdb1599c
Author: My Name
Date: Thu Apr 2 18:02:30 2009 +0900
lm-7.0betaK001 09.03.30
(Internally you changed to another noname branch from master branch. The warning message says such things. ) You can't see other branches. Let's go back again to the original one. To do it, we must specify the branch.
$ git checkout master
to find that your changes are restored. The more appropriate way is to specify a new branch name.
$ git checkout -b expr 6ff09b732e4d9913a2eb9bd72c57c104cdb1599c
Switched to a new branch "expr"
$ git branch
* expr
master
$ git log
commit 6ff09b732e4d9913a2eb9bd72c57c104cdb1599c
Author: My Name
Date: Thu Apr 2 18:02:30 2009 +0900
lm-7.0betaK001 09.03.30
$ git checkout master
Switched to branch "master"
$ git log
commit 72979cde141b81c7a6058a135f09c7ee1b57d2dc
Author: My Name
Date: Thu Apr 2 18:03:54 2009 +0900
MODDIR -> $(moddir)
commit 6ff09b732e4d9913a2eb9bd72c57c104cdb1599c
Author: My Name
Date: Thu Apr 2 18:02:30 2009 +0900
lm-7.0betaK001 09.03.30
You can make and move to a new branch to test new functions
$ git branch test-mkl $ git checkout test-mkl
You can make and move to a new branch to test new functions
$ git branch test-mkl $ git checkout test-mkl
Now your branch is test-mkl, but the content is the same as the last one. You can come back to other branches at any time
$ git checkout master
To remove a branch,
$ git branch -d test-mkl
[編集] repository or clone
[編集] making repository in another directory
$ mkdir ~/proj $ git clone . ~/proj/lm-7.0betaK001
~/proj/lm-7.0betaK00 is a clone of your working directory and it is also a repository. Then change Makefile in ~/proj/lm-7.0betaK001. (It's only a clone of the original directory.)
$ pwd /home/myname/proj/lm-7.0betaK001 $ ls CPPCHECK.sh MAKEINC Makefile TESTsamples fp lmf2gw.F mergemto.py packlmf.with.fftw subs FPLOTdir MODDIR MarksOriginalDoc TOOLS gwd lmfav7.F nc rdcmd.F tb GetStarted.html Make.inc TAGS ctrlgen.py lm67.F lmv7.F packlmf slatsm tbe.F
Here I change Makefile. After that,
$ git add Makefile
$ git commit
$ git log
commit 76e231626c02ce66bf5d10227adc0f5ea53cd3bc
Author: My Name
Date: Thu Apr 2 17:32:30 2009 +0900
add: if [ -e $(moddir)]; then ... mkdir $(moddir)...
commit 2f166487c789ef36a14310dec270b011f65707d7
Author: My Name
Date: Thu Apr 2 17:00:09 2009 +0900
MODIR -> $(moddir)
commit 27712d01855844d80a12578d799430c5162a8986
Author: My Name
Date: Thu Apr 2 16:52:40 2009 +0900
lm-7.0betaK001 09.03.30
Now I have a commit 76e2316... git can use ssh and other internet communication like
$ git clone ssh://host_name/home/myname/kit/GW/lm-7.0betaK001.090330 new-source
Here new-source/ directory contains the same files as those in host_name:/home/myname/kit/GW/lm-7.0betaK001.090330. See also man git-clone. It is also possible to clone only .git/ directory
$ mkdir ~/proj/lm-7.0betaK002/ $ git clone --bare . ~/proj/lm-7.0betaK002/.git
It makes only .git/ directory in lm-7.0betaK002/. You can restore all the files.
$ cd ~/proj/lm-7.0betaK002 $ git init $ git checkout -f
[編集] merge
Let's merge them at the original working directory.
$ pwd
/home/myname/kit/GW/lm-7.0betaK001.090330
$ git pull /home/myname/proj/lm-7.0betaK001 master
$ git log
commit 76e231626c02ce66bf5d10227adc0f5ea53cd3bc
Author: My Name
Date: Thu Apr 2 17:32:30 2009 +0900
add: if [ -e $(moddir)]; then ... mkdir $(moddir)...
commit 2f166487c789ef36a14310dec270b011f65707d7
Author: My Name
Date: Thu Apr 2 17:00:09 2009 +0900
MODIR -> $(moddir)
commit 27712d01855844d80a12578d799430c5162a8986
Author: My Name
Date: Thu Apr 2 16:52:40 2009 +0900
lm-7.0betaK001 09.03.30
[編集] tar ball
tar ball
$ git archive --format=tar --prefix=lm-v7.0betaK002/ HEAD | gzip >lm-v7betaK-latest.tar.gz
where HEAD is an abbreviation of the newest commit. You can specify other hex numbers. / of --prefix=lm-v7.0betaK002/ is also important to specify the directory name. If --prefix=lm-v7.0betaK002, your extracted files will be
lm-v7.0betaK002Makefile lm-v7.0betaK002Make.inc lm-v7.0betaK002fp/ ...
I mean that no directory lm-v7.0betaK002 is made. Note that this tar ball doesn't contain any repository information, or .git/ directory.
[編集] github
[編集] proxy
proxyを使ってwebが見えるならば、corkscrewを使ってgithubも利用可能。
- corkscrewはhttp proxyを使ってssh通信を行う。
設定方法
- install corkscrew [[1]]
- edit ./ssh/config
Host github.com User git Hostname ssh.github.com Port 443 ProxyCommand corkscrew httpproxyname httpproxyport %h %p
httpproxyname httpproxyportはweb browserの設定と同じ。 つながるとsshのpass phraseを聞かれる。
[編集] reposityの取かた
[download]でtar.gzが取れる。repositoryを取るには
$ git clone ssh://github.com/nim-hrkn/pmt.git
とするとpmt/ directoryにファイルできる。[git clone ssh://github.com/nim-hrkn/pmt.git pmt2]とdirectory指定も可能。
