HEAD

  • HEAD
  • HEAD~ or HEAD~1
  • HEAD~~ or HEAD~2
  • HEAD~~~ or HEAD~3
  • HEAD~~~~ or HEAD~4
  • ........

gitk

GUIなlog, diffビュワー。コマンドを覚えるのも重要だが、さくっと見るだけならかなり便利。branch, mergeの様子もよくわかる。CUIでは「git log --graph」を使用。マニュアルは以下から。

git clone

git clone URLclone the git repository

Example w/ healpy,

git clone https://github.com/healpy/healpy.git

and you can get

git clone https://github.com/healpy/healpy.git
Cloning into 'healpy'...
remote: Counting objects: 5503, done.
remote: Compressing objects: 100% (5/5), done.
remote: Total 5503 (delta 0), reused 1 (delta 0), pack-reused 5498
Receiving objects: 100% (5503/5503), 15.58 MiB | 10.17 MiB/s, done.
Resolving deltas: 100% (3006/3006), done.
Checking connectivity... done.
[chinoney@yMacBookPro:~ ] $ ls healpy

(not healpy.git)

git config

git config --global user.name "Hoge Huga"
git config --global user.email aho@example.com

git remote

git remote -v

check remote URL

git log

git logshow log
git log -p -2shows the diff introduced in each commit and limit output number

git reflog

git reflogshow all changes even though they are not referenced by any branch or tag. E.g git reset --hard HEAD@{2}

git checkout

git checkout -- <file>discard changes (revert in subversion)
git checkout <branch> -- <file>import <file> from <branch>
git checkout <target>change current branch
git checkout <hash>back to certain version of repository
git checkout <hash> <file>back to certain version of file

一時的に以前の状態に戻る:

$ git checkout cea7f5a45fa7d9f29f7ae7cXXXXXXXXX
$ git branch
$ * (no branch)
   master
   unbiased-mapmaking
$ git checkout master

git reset

git reset HEAD <file>unstage file
git reset --hard <hash>back to <hash> (commit deleted)

git branch

git branchget a simple listing of the current branches
git branch -aget a simple listing of all the branches
git branch -vsee the last commit one each branch
git branch <target>make new branch
git checkout <target>switch target branch
git branch -b <target>make new branch and switch it at the same time
git branch -d <target>delete target branch
git branch <target> origin/<target>pull a target branch
git pull origin <target>pull a target branch and make a merge (dangerous)

git cherry-pick

git cherry-pick <SHA1>apply the changes introduced by some existing commits

git merge

git merge <target>merge target branch with the current branch

git show

git show <SHA1>:<target>show target on SHA1 revision
git show <branch>:<target>show target on a branch

git pull

git pullFetch from and integrate with another repository
git pull --rebaseit runs git rebase instead of git merge

git push

git pushUpdate remote refs along with associated objects

git cat-file

git cat-file -p <SHA1>:<target>cat target on SHA1 revision

tips

make a new branch from master before merged/pushed and revert the original branch to origin

git status
# On branch master
# Your branch and 'origin/master' have diverged,
# and have 64 and 6 different commit(s) each, respectively.

Check how much different btw HEAD and origin/master

git log origin/master..HEAD
git show origin/master..HEAD

Make a new branch from HEAD

git checkout -b new_branch

Then delete the master

git branch -d master

or

git branch -D master

and download the master from the origin

git fetch
git checkout master

Push the new branch if you want

git push -u origin new_branch