레이블이 stash인 게시물을 표시합니다. 모든 게시물 표시
레이블이 stash인 게시물을 표시합니다. 모든 게시물 표시

10.04.2020

Studying Basic GIT(init, add, commit, branch, merge, stash)

This summary is based on a very useful tutorial. (not English, but Korean)


  • What is GIT?

    → Version Control System

Basic Commands of GIT

  • git init

  • git add

    • Why should I do git add before git commit ?

      It makes you possible to choose what to commit.

      It great when you have done massive changes on your code, but forgot to commit by each feature.

      We call stage area when you add but didn't commit.

      After commit, it goes to repository .

  • git status

    → It will show you what has been added(tracked) and what has not.

  • git config —global user.name <your name>

  • git config —global user.email <your email>

    → If you are using git for the first time, you need to configure git account to let git and others know who is making the commits.

  • git commit

    → activate vim for writing commit message

    shortcut git commit -m <your message>

  • git log

    → It will show you the history of commit that you made.

  • git log -p

    → you can see the differences between each commit

  • git diff <A commit id>..<B commit id>

    → It will show you the differences between A commit and B commit in a source level.

  • UNDO the commit

    1. reset
      • git reset <commit id that you want to go back to> — hard
      • the version after above commit will be disappear.
      • You will ONLY can reset the commit on your local.(can't reset already pushed one)
    2. revert
      • remove the target commit and create a new commit.

How GIT Works

  • index(also called cache, staging area)

    • Index contains the file names that have been added, and the location address of that file in the objects folder.

    • It uses SHA1 hash function to generate file directory name(first two letter of the hash string), and file name(left over hash string).

      → SO, If the contents of two different file is exactly same, then git reuses the previous one. (means that git does not create another objects file)

  • objects

    • The objects directory is the one contains the source code that has been git add .
    • The name of the file and the directory name which contains the target file are come from the hash string. So it doesn't contain the file name.(index does)
    • It also contains the commit log.
      • The commit object has two important infomations.
        1. tree(also called snapshot )

          → pointing the object that contains addresses of this version files.

          →The type of each file is blob .

        2. parent

          → pointing the object that contains addresses of previous version files.

  • GIT compares most recent index and commit objects, and make decisions.(git status messages)

GIT Branch

  • git branch

    → show all branches and let us know which one we're in

  • git branch <new branch name>

  • git checkout <branch name that you want to be in>

    shortcut git checkout -b <new branch name that you want to create and want to be in at the same time>

  • git log —branches —decorate —graph <optional : —oneline>

    → show git log with branches states and show us branch graph

  • git diff master..<other branch> || git log master..<other branch>

    → show us differences between two branchs

  • (if you want to merge A to B, you must checkout to B) git merge A

  • git branch -d <branch name that you want to delete>

  • git stash [save]

    stash command let you save current changes like a temporary commit, you don't actually write the commit command though.

    → you can skip the save command.

  • git stash list

    → It shows all the stashed log.

  • git stash apply

    →It brings back most recent stashed state, so that you can continue with your work.

    → It is helpful to type git status to understand how stash works.

  • git stash drop

    → It deletes most recent stash log.

    shortcut git stash pop(apply and drop)

  • git reset — hard HEAD

    → It roll back the current state to the most recent commit(not stash one, but actuall commit).

  • alert git stash ONLY handle the file that is being tracked to git. So, for example, if you have a new file that you never added before, then stash cannot handle that file.

Share: