Git basic operation


1: Basic exercises

1: Create a version Library

  • In the project folder, execute
git init

Git basic operation

2: Submission of documents

  • After creating a new file, view the file content instructions

    git status

  • Add file to staging

    Git add file name

Git basic operation

  • Submit documents to local warehouse

    git commit

  • Write comments and complete the submission

Git basic operation

The operation here is consistent with that in Linux system.
After entering the edit page, press I to start writing the content.
After writing the comments, press ESC first, and then press: WQ to save the contents and exit.

Git basic operation

  • You can also submit directly with comments

    Git commit – M comment content

Git basic operation

3: View file submission history

  • View history

    Git log file name

Git basic operation

  • Simple information view

    Git log — pretty = oneline file name

Git basic operation

4: Retrogression history

  • Fallback one submission (back to previous)

    git reset –hard HEAD^

  • Back n submission

    git reset –hard HEAD~n

5: Version traversal

  • View the version number of the history

    Git reflog file name

Git basic operation

  • Crossing ~ (don’t misunderstand, HHH)

    Git reset — hard version number

Git basic operation

6: Restore files

Git checkout — file name

7: Delete file

  • Delete file first
  • In Git add, submit again

8: Workspace + staging + local library

Git basic operation

2: Branching

1: Create branch

Git branch branch name
Git branch – V view branch

Git basic operation

2: Switch branches

Git checkout branch name
Git basic operation

Create and switch in one step

Git checkout – B branch name

Git basic operation

3: Merge branches

  • Switch to the trunk first

git checkout master

  • merge

Git merge branch name

Git basic operation

4: Delete branch

  • Switch to the trunk first
  • Delete branch

Git branch – D branch name

5: Conflict

  • Concept: conflict generally refers to the code in the same location of the same file. When two versions are merged, the version management software can’t determine which version should be kept. Therefore, it will prompt the file to send the conflict, and manual judgment is needed to solve the conflict
  • Conflict during merging: conflict will prompt conflict keyword when program merging, and command line suffix will enter merging state, indicating that it is in conflict resolution state at this time.

Git basic operation

  • Conflict resolution

Git diff can be used to find the conflict file and the conflict content

Git basic operation

Then modify the content of the conflicting file. After modification, GIT add and git commit are submitted again. The suffix merge disappears, and the conflict resolution is completed

Git basic operation