Getting started with GIT and GitHub 01



Git basic operation

1、 Git’s three warehouses

  • Git local warehouse has three areas: working area, temporary storage area and version area.

Getting started with GIT and GitHub 01

Make changes to the workspace

  • Execute git status to view the status of the whole warehouse

    [email protected] MINGW64 ~/shiyanlou (master)
    $ git status
    On branch master
    Your branch is up to date with 'origin/master'.
    nothing to commit, working tree clean
  • create a file

    $ echo 'hello world'>one.txt

Add changes to the scratch pad and undo changes

  • Use the GIT add command to track this new file
  • If you add, delete or modify multiple files or directories, you can use the GIT add. Command to add them all to the temporary storage area.
  • To undo the modification of the buffer, execute git reset — [file name] or git RM — cached [file name] command
  • Git diff, which can be used to view the modification details of the tracked files in the workspace. Only the files existing in the version area are tracked files.

View submission history

  • Git commit command submits the modification of the buffer to the version area to generate a new version.
  • Git log, which is used to view the submission history of the version area
  • Git log [branch name] view the submission history of a branch, and view the current branch without writing the branch name
  • Git log — oneline displays the submission history
  • Git log – n where n is the number to view the latest n submissions
  • Git log — author [contributor name] view the submission record of the specified contributor
  • Git log — graph to display submission history

Configure personal information

  • Git config – L to view configuration information

Submit changes to staging area

  • The GIT commit command generates a new commit
  • Execute git log to view the submission record
  • To view the information in positive time order, you can use the GIT log — reverse command
  • Git branch – AVV is used to view all branch information
  • Git push pushes the newly added local submission to GitHub remote warehouse

Version rollback

  • Discovery one.txt If the file content is wrong, execute git reset — soft head ^ to cancel the latest submission and restore the modification to the temporary storage. –Soft means soft return, corresponding to hard return. As will be mentioned later, head ^ means to cancel one submission, head ^ means to cancel two submissions, and N times of cancellation can be abbreviated as head ~ n.

Handle commit timeline bifurcation

  • If there is a conflict between the master branch of the local warehouse and the origin / Master branch of the remote warehouse in the submission version, and the submission timeline bifurcates, in this case, the local master branch can also be pushed to the remote warehouse. You need to add an option – F, which is short for — force, which is forced push.

Commit change record of local warehouse

  • Git reflog will record every version change of all branches of the local warehouse
  • Reflog records only exist in the local warehouse. After the local warehouse is deleted, the records disappear
  • Execute the command git reset — hard to go back to the specified version