Home 3.basic
Post
Cancel

3.basic

이후 방향

  • 상태가 어떻고 하는 그런 자세한걸 쓰고싶은데 난 잘 모르니까 아는선에서 정리만하는걸로.
  • 더 좋은게 있으면 추가.
  • local -> remote 방향으로하면 git 자체 명령어도 보고 다음 gitlab이나 github같은 외부 저장소 쓰는 방법으로 확장도 좋을것같음.

명령어

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
$ git --help
usage: git [--version] [--help] [-C <path>] [-c <name>=<value>]
           [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
           [-p | --paginate | -P | --no-pager] [--no-replace-objects] [--bare]
           [--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
           <command> [<args>]

These are common Git commands used in various situations:

start a working area (see also: git help tutorial)
   clone             Clone a repository into a new directory
   init              Create an empty Git repository or reinitialize an existing one

work on the current change (see also: git help everyday)
   add               Add file contents to the index
   mv                Move or rename a file, a directory, or a symlink
   restore           Restore working tree files
   rm                Remove files from the working tree and from the index
   sparse-checkout   Initialize and modify the sparse-checkout

examine the history and state (see also: git help revisions)
   bisect            Use binary search to find the commit that introduced a bug
   diff              Show changes between commits, commit and working tree, etc
   grep              Print lines matching a pattern
   log               Show commit logs
   show              Show various types of objects
   status            Show the working tree status

grow, mark and tweak your common history
   branch            List, create, or delete branches
   commit            Record changes to the repository
   merge             Join two or more development histories together
   rebase            Reapply commits on top of another base tip
   reset             Reset current HEAD to the specified state
   switch            Switch branches
   tag               Create, list, delete or verify a tag object signed with GPG

collaborate (see also: git help workflows)
   fetch             Download objects and refs from another repository
   pull              Fetch from and integrate with another repository or a local branch
   push              Update remote refs along with associated objects

'git help -a' and 'git help -g' list available subcommands and some
concept guides. See 'git help <command>' or 'git help <concept>'
to read about a specific subcommand or concept.
See 'git help git' for an overview of the system.
  • 이중에 clone, init, add, log, status, branch, commit, pull, push, switch 정도 많이 쓰고
    merge, rebase, diff 같은건 익숙해져야함.

git init - 저장소 만들기

  • git init 하면 .git폴더가 하나 생성됨
  • git는 수정된 복사본을 생성하는 방식이 아니라 번경된 내용과 시점만 저장하는식으로 하는데 그 정보가 들어가는게 저 폴더인것같음.
  • 요거 하면 그 전까지 일반 dir로 표시되던것에 (master)가 생김.
    1
    2
    3
    4
    5
    6
    
    psy02@psy-aw MINGW64 /d/Workspace/Blog/git_test/Proj_1
    $ git init
    Initialized empty Git repository in D:/Workspace/Blog/git_test/Proj_1/.git/
    
    psy02@psy-aw MINGW64 /d/Workspace/Blog/git_test/Proj_1 (master)
    $
    
  • 이제부터 git에서 관리해주는거임

git add

  • Proj_1안에는 .git 폴더 하나만 있는데 여기 1.md 하나 생성하고 git status를 하면
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    
     $ git status
     On branch master
    
     No commits yet
    
     Untracked files:
     (use "git add <file>..." to include in what will be committed)
           1.md
    
     nothing added to commit but untracked files present (use "git add" to track)
    
  • 1.md는 Untracked file 이라 함. 말그대로 추적하지 않음.
  • 이걸 git add하면 그때부터 알고있던 git의 기능을 쓸 수 있음
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    
     $ git add 1.md
    
     $ git status
     On branch master
    
     No commits yet
    
     Changes to be committed:
     (use "git rm --cached <file>..." to unstage)
           new file:   1.md
    
  • 이렇게 되면 이제 1.md에 대한 수정 등을 추적가능함.
  • 위는 “git add 1.md” 해서 하나만 add했는데 “git add .” 으로 이렉터리 전체 다 add가능함. 반대로 여러 수정사항이 있는경우 commit 남길만한 것들만 add해서 관라가능.

git commit

  • commit는 게임으로치면 save.
  • 외부 수업으로 배울때도 commit관련 내용이 많았는데 그만큼 중요함.
  • 다시한번, 게임으로 치면 save. 띠리서 이 저장 기록으로 되돌릴수도 있고 저장기록을 지울수도, 그 저장기록까지의 내용을 합칠수도있음.
  • 그 자세한건 나중에 더 쓰기로. 하고 일단
    1
    
     $ git commit 
    
  • 이거 하면 설치할때 기본 에디터로 지정해놓은걸로 넘어가고 commit는 commit message가 꼭 있어야 가능함.
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    
     commit msg
     commit msg
     commit msg
     # Please enter the commit message for your changes. Lines starting
     # with '#' will be ignored, and an empty message aborts the commit.
     #
     # On branch master
     #
     # Initial commit
     #
     # Changes to be committed:
     #       new file:   1.md
     #
     ~
     ~
    
  • commit msg가 commit message이고 나머지 아래가 그냥 생성된것들. 무튼 요거 저장하면
    1
    2
    3
    4
    5
    6
    7
    
     $ git commit
     [master (root-commit) 12ed4f4] commit msg commit msg commit msg
     1 file changed, 0 insertions(+), 0 deletions(-)
     create mode 100644 1.md
     $ git status
     On branch master
     nothing to commit, working tree clean
    
    • 이렇게 빠짐. 그 아래 status에서 확인해보면 clean으로 정상적으로 다 끝난상태. 이걸 다시 확인하려면
      1
      2
      3
      4
      5
      6
      7
      8
      
       $ git log
       commit 12ed4f4cde32d1d65d78883e3eead0fe63811fe9 (HEAD -> master)
       Author: psy_aw <psy0231@gmail.com>
       Date:   Fri May 1 19:47:40 2020 +0900
      
       commit msg
       commit msg
       commit msg
      
  • 아까 남긴 commit message확인할 수 있다.
  • 근데 이렇게 길게 남기는일이 아직 없어서
    git commit -m “commit message”
    이렇게 끝내는게 보통.

cycle

  • 위 까지의 과정이 아주 간단히 쓰는 보통 한 사이클이고 외부 저장소 없이 사용하는 경우임.
  • init -> add -> commit 에서 이후 수정분에 대해 add -> commit 계속 하는식.
  • 중간중간 계속 save point를 만들어 간다 생각하자.
  • image
  • 그래서 보통 많이 볼 수 있는게 위 설명인데
    • 처음 파일이 만들어지면 Untracked
    • Untracked를 add하면 Staged이고 commit를 기다리는상태.
    • staged를 commit 하면 Unmodified tkdxo == clean 상태라 나옴.
    • 수정하면 Modified상테로 감.
    • 어떤 변경 작업 시 그냥은 commit이 안되고 add를 선행해야 stage상태가 되어 commit를 할 수 있음.
  • staged상태만 commit할수 있고 staged를 만드는게 add라고 생각하면 편한듯.

상태 확인 명령어

git status

  • 또 많이 쓰는 명령어.
  • 처음엔 파일 상태를 보는 건줄알았는데 지금 적업중인 상태를 본다는게 좀더 맞는듯함.
  • 이거 중간중간 치면서 하면 좋다.
  • git status -s

git log

  • commit 기록 볼 수 있음
  • git log –oneline

git show

git shortlog

참고

This post is licensed under CC BY 4.0 by the author.

2.설치, 기본설정

4. reset, revert

Comments powered by Disqus.