LoginSignup
0
0

More than 3 years have passed since last update.

git

Last updated at Posted at 2019-05-26
git基本設定

初期のディレクトり

Hello
 - hello.rb

$git init 実行
※gitは隠しファイル(ls -aで見れる)

Hello
 - hello.rb
 - .git
   - HEAD
   - config(設定ファイル)
   - などなど


ディレクトリ
$ ls -C .git
COMMIT_EDITMSG  ORIG_HEAD   hooks       logs        rr-cache
HEAD        config      index       objects
MERGE_RR    description info        refs


- objects
変更した履歴?

- HEAD
最新の状態
基本コマンド

git add
git status
git commit -m "コミットメッセージ"
git checkout
git reset
git log
git log --pretty=oneline(commit の名前だけ見れる)
git log --pretty=oneline --max-count=2
git log --pretty=oneline --since='5 minutes ago'
git log --pretty=oneline --until='5 minutes ago'(編集時間でソート)
git log --pretty=oneline --author=<your name>(編集者でソート)
git log --pretty=oneline --all
gitconfigの設定
[alias]
  co = checkout
  ci = commit
  st = status
  br = branch
  hist = log --pretty=format:'%h %ad | %s%d [%an]' --graph --date=short
  type = cat-file -t
  dump = cat-file -p
戻る
git checkout <hash>
git checkot master(これで戻れる。。。。) 

hash値にgcした時のブランチを見ると。。。。

$ git branch
* (HEAD detached at ef8ce92)
  master
addの取り消し

$ git status
On branch master
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

    modified:   hello.rb(緑)

addから外す

$ git reset HEAD hello.rb



$ git status
On branch master
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

    modified:   hello.rb(赤)
revert

commit 2b8bec385230a923f6d1866a61b5fa5919967969 (HEAD -> master)
Author: Awtanabe <panser098@gmail.com>
Date:   Sun May 26 22:24:31 2019 +0900

    Revert "for revert"

    This reverts commit df9de155eedb95f08f083578d874d97a9918e6be.

commit df9de155eedb95f08f083578d874d97a9918e6be
Author: Awtanabe <panser098@gmail.com>
Date:   Sun May 26 22:24:16 2019 +0900

    for revert

※revertした履歴も残る!!
 共同開発して勝手に消されたら困るもんね。
コミットの編集

git commit --amend -m "Add an author/email comment"
ファイルの場所を変更

git mv hello.rb lib

git つけるんだ

git をつけないと...


$ git status
On branch master
Changes not staged for commit:
  (use "git add/rm <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

    deleted:    hello.rb

Untracked files:
  (use "git add <file>..." to include in what will be committed)

    lib/


hello.rbがdeleteされて
libのデレクトダケができる

ちゃんとやると

$ git mv hello.rb lib/

watanabeakifumi-no-MacBook-Air:hello watanabeakifumi$ git status
On branch master
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

    renamed:    hello.rb -> lib/hello.rb

Raketaskの実行

Rakefile(ファイル名)
#!/usr/bin/ruby -wKU

task :default => :run

task :run do
  require './lib/hello'
end

$ rake 
→ helloworld

rake で実行すると、defaultのtaskが実行されるのか

ブランチ作成
git branch <ブランチ名>
rebaseとコンプリくと
$ git rebase <含みたいブランチ>


1 コンフリクト発生
2 >>>で検索する
3 解消する
4 git add -A
5 git rebase --continue 修正終わったら
※一つづつ解決する

コンフリクトの解消

コンフリクト発生
$ git merge master
Auto-merging lib/hello.rb
CONFLICT (content): Merge conflict in lib/hello.rb
Automatic merge failed; fix conflicts and then commit the result.

リモートブランチ
$ git remote -v
$ git branch -a(リモートブランチ一覧)
$ git remote add shared ../hello.git(リモートに追加)
Todo

fetch 
pull 
bare
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0