Lipsky

The usage of git

字数统计: 367阅读时长: 2 min
2018/04/13 Share

Install#

  • Linux

    • check whether exist a version of git

      1
      $git
    • Debain/Utuntu linux

      1
      sudo apt-get install git
  • Mac OS

    • install by homebrew

      view

  • windows

    • skip

After installed, run in terminal:#

1
2
$git config --global user.name "Your name"
$git config --global user.email "[email protected]"

To create a store#

  • first

    1
    2
    $mkdir learngit
    $cd learngit
  • second
    init the git store

    1
    $git init

To wirite a file#

example:

1
2
git is a version control system.
git is free software.

Then submit to git#

  • step one

    1
    $git add "file name"
  • step two

    1
    $git commit -m "write what you want to record"

Backup to the previous version#

  • back to last version of the workspace

    1
    2
    $git log // show the log
    $git reset --hard HEAD^ // reset to the last verson of the workspace
  • back to old one besides last version

    1
    $git log // to view id of last log

example :the old version id is xxxxxxxxxxxxx
you can use the command to back to that version

1
$git reset --hard xxxx(can use several previous number of the id )

  • After you use the back command above, you also want to back again.
    1
    $git relog //this command to log the command you have code(only the present terminal window is not closed.)

find the id of the old persion you want to back up, then use the command with id to back up.

1
$git reset --hard xxxx(the id )

When you want to abort the file in workspace#

use the command

1
2
$git checkout --"file name"
$git status //view the status of workspace

only you don’t submit to git store using the command “git commit -m “what you want to record”, can you abort the changes.

Delete the file#

  • When you delete the file in file manager or delete file in terminal,then you want to delete them forever.

    1
    2
    $git rm "file name"
    $git commit -m "remove 'file name'" //delete the file in git store
  • Second situation, you just delete by mistake/accident, you can restore from git version store.

    1
    $git checkout --"file name" //use the abort command.
CATALOG
  1. 1. Install#
  2. 2. After installed, run in terminal:#
  3. 3. To create a store#
  4. 4. To wirite a file#
  5. 5. Then submit to git#
  6. 6. Backup to the previous version#
  7. 7. When you want to abort the file in workspace#
  8. 8. Delete the file#