Git Basics

9yur1·2022년 5월 4일
0

🍰 CS

목록 보기
2/3
post-thumbnail

🔷 Version Control

Open source

  • Anyone can download and suggest changes.

Linux

  • a major open source
  • Thousands of regular developers, millions of files
  • Developers spread over the globe across multiple time zones

Version Control System

  • Manage these things using a version control system (VCS)
  • A version control system allows for the management of a code base.

Repository 레포지토리

  • Repository : a location storing a copy of all files.
    • You don't edit files directly in the repo
    • You edit a local working copy or working tree
    • You commit your edited files into the repo
  • Files in your working directory must be added to the repo in order to be tracked.

What to put in a Repo?

  • Source code (Ex: .java, .c, .h, .cpp)
  • Build configuration files (Makefile, build.xml)
  • Other resources : icons, text etc.
  • Things generally NOT put in a repo
    • Object files (.o)
    • Executables (.exe)

More Uses of Version Control

  • VCS is essential for quality source code development

  • Undo changes to a file

    • Like "undo" in an editor
    • Keep the whole history of every file and a changelog
  • Who changed what, when

Essential features

  • Check-in and Check-out (Upload/Download) of items to repository
  • Creation of baselines (labels/tags)
    • Version 1.0 released!
  • Control and manipulation of branching
    • management of multiple versions
  • Overview of version history
  1. Centrallized Version Control
    • A single server holds the code base
    • Code is shared by check-in/check-outs
    • CVS, Subversion, Visual Source Safe
    • Advantage
      • Easier to maintain a single server
    • Disadvantage
      • Single point of failure.
  1. Distributed Version Control
    • Each client holds a complete copy of the code base.
    • Code is shared by push/pulls
    • Advantages
      • Many to operations cheaper
      • No single point of failure
    • Disadvantages
      • A bit more complicated!

🔷 Git

Git Advantages

  • Resilence
    : Distributed multiple repositories
  • Speed
    : Very fast operations compared to other VCS
  • Space
    • Compression can be done across repository not just per file
    • Minimizes local size as well as push/pull data transfers
  • Simplicity
    : Object model is very simple
  • Large userbase

Git Disadvantages

  • Learning Curve
    • Hard to learn
    • Comceptual difference from centralized version control
    • Huge amount of commands

A Local Git project has three areas

1. Working directory

  • Sometimes called the "working tree"
  • The area where you are currently working (Your files)

2. Staging Area

  • Also known as the "index"
  • Tracking and savings changes
  • Prepare for a commit
  • Stored in .git/index

3. Repository (local)

  • Commits, branches and other things are stored in the repository
  • Everything in your .git directory

Git file lifecycle

Basic Flow

  1. Init clone a repo
  2. Edit files
  3. Stage the changes
  4. Review your changes
  5. Commit the changes
git init
git clone "ssh or http of git repo"
# file editing ...
git status
git add file.txt
git rm file.txt
git commit -m "commit message"
git push

git init 을 통해 local 폴더에서 git을 시작.
git clone 을 통해 local 폴더와 연결할 git의 repository의 주소를 입력하여 연결.
로컬에서 파일을 수정한 후 git status 를 입력하면 local 폴더에서 아직 stage에 올라가지 못한 변경사항이 있는 파일들을 보여줌.
git add 명령어를 통해 그러한 파일들을 stage에 올려줌. git add filename.확장자를 입력해준다. 만약 모든 변경 된 파일을 올려주고 싶다면 git add *를 입력.
git rm 명령어는 add한 file을 지우고 싶을 때 사용.
git commit 명령어는 스테이지에 있는 파일들을 repository로 올려줌. 이 때, 커밋 메세지를 함께 입력해야하는데, 만약 커밋 메세지로 "Version updated"를 작성하고 싶다면, 두 가지 방법이 있다.
git commit -m "Version updated" 를 git bash에 입력하거나, git commit을 입력하면 텍스트파일이 뜨는데 거기에 "Version updated"를 적고 창을 닫으면 된다.

여기까지가 기본적인 git 의 명령어이고, 그 밖의 명령어는 다음과 같다.
git diff : working directory 와 stage의 차이점을 보여줌.
git diff -cached : stage와 repository의 차이점을 보여줌.
git log : 지금까지 history를 보여줌.

profile
Best results with extreme efficiency

0개의 댓글