LoginSignup
9

More than 5 years have passed since last update.

デザイナーも学ぶgitと使えるコマンド

Last updated at Posted at 2016-01-26

はじめに

サービス開発をしていく中でデザイナーやフロントエンドの人たち一緒に仕事をします。
エディターとかは個人の使いやすいもので良いのですが、ソース管理は皆大体gitを使ってエンジニアと連携します。
その際に利用する実践的なgitコマンドを紹介します。

なぜ学んだ方が良いかというと

SourceTreeを利用すればコマンドを覚えなくてもできますが、

  1. 大体の人はSourceTreeの正常系の使い方を覚える
  2. 操作を誤りよくわから状態になり、エンジニアHelp
  3. エンジニアでSourceTreeをよく知ってる人はほぼいない。コマンドでできるからあまり覚えようとしない
  4. エンジニアはコマンド上で元に戻す

といった感じで毎度同じことを繰り返してしまい、生産的でないのでデザイナーにもgitコマンドで操作してしまえば良いんじゃね?と思った。

まぁ色々な会社さんでもエンジニア以外の人がgitコマンドを使うのって結構普通だったりするので

全部説明すると果てしなく長いので最小限にとどめます。興味がわいたコマンドは検索してさらに理解を深めてもらえればと

基本の作りとか

ルートディレクトリ/-.git              // gitのメインディレクトリ
                |   |-.git/config   // config設定。最初だけいじる
                |- .gitignore       // gitで管理しないファイルを指定
                |- .gitkeep         // 空ディレクトリもgit管理したい場合使う

そもそもgitって

分散型バージョン管理システム。まぁソースを管理するtool。

基本コマンド

最初だけ使うコマンド

  • git管理されたプロジェクトをコピー

    cd [コピーしたいディレクトリパス]
    git clone [リモートリポジトリ名]
    

    または

    git clone [リモートリポジトリ名] [コピーしたいディレクトリパス]
    
  • 新規でgit管理したい場合

    管理したいディレクトルートで
    git init
    
    • 途中コンソールから何か入力を求められてもyesで進んでおけばok
    • 後で.git/configを修正するば設定可能

日々使うコマンド

branch系

git branch <branch_name>  //ブランチの作成(作るだけで移動しない)
git checkout -b <branch_name> //ブランチを作成して移動する
git checkout <branch_name>  //ブランチの移動
git branch -d <branch_name>  //ブランチの削除
git branch -m <branch_name>  //現在のブランチ名の変更
git branch // ローカルブランチの一覧
git branch -a //リモートとローカルのブランチの一覧
git branch -r //リモートブランチの一覧

※これらのコマンドをする前にgit statusでキレイな状態にしてからやると混乱しない

status系

  • 現在の状態を知る(何も新規追加も変種も削除もしていない状態)

    git status
    # On branch feature/<branch_name>
    nothing to commit (working directory clean)
    
  • 現在の状態を知る(aaaと云う新規ファイルを追加した場合)

    git status
    # On branch feature/<branch_name>
    # Untracked files:
    #   (use "git add <file>..." to include in what will be committed)  
    #
    #   aaa     nothing added to commit but untracked files present (use "git add" to track)                
    
  • 現在の状態を知る(test.txtと云うファイルを編集した場合)

    # On branch feature/<branch_name>
    # Changed but not updated:
    #   (use "git add <file>..." to update what will be committed)
    #   (use "git checkout -- <file>..." to discard changes in working directory)
    #
    #   modified:   test.txt
    #
    no changes added to commit (use "git add" and/or "git commit -a")
    
  • 現在の状態を知る(test.txtと云うファイルを削除した場合)

    # On branch feature/<branch_name>
    # Changed but not updated:
    #   (use "git add/rm <file>..." to update what will be committed)
    #   (use "git checkout -- <file>..." to discard changes in working directory)
    #
    #   deleted:    test.txt
    #
    no changes added to commit (use "git add" and/or "git commit -a")
    

コミット

git commit -a
テキストエディタ(大体vim)が立ち上がる
test file追加
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
# On branch feature/o_205_cf_bank_validation
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#       modified:   test.txt
#

コマンドモード[esc]に切り替え[:wp]で保存
[:q!]やれば戻る

差分を見る

git diff系コマンドで観れるけど見づらいのでpushしてgithub上で観た方が良い

修正したファイルを戻す

  • commit前の場合

    git checkout <対象のファイル>
    
  • commit後の場合

    git log <対象のファイルパス> //<対象のファイルパス>の変更履歴をを参照
    commit コミット番号
    Author: vvvvv <vvvv@example.com>
    Date:   Wed Sep 9 15:31:24 2015 +0900
    コミットメッセージ
    ...
    git checkout <コミット番号> <対象のファイルパス>
    

中央レポジトリにpush

git push origin <branch_name>

originは.git/configに設定してある
大体の場合はgithubのパスが書いてると思う

備考

  • 利用しているgitはgit version 1.7.1

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
9