Common commands

  • Ls View the files in the current folder
  • Ls -a/ls-ah View files in the current folder (including hidden files eg:.get.history.idea…)
  • The PWD displays the current directory (eg: / d/WorkSpace/project/kol – Editor – the Sop/kol – Editor – Sop/resources)
  • Mkdir Folder name To create a folder
  • Touch file name create file
  • Ls -la View all files in this directory (including hidden files)
  • Dir View the file directory in the folder
  • D: Go to the file directory
  • Cat file name View the file content

1. Install Git and configure git

Git-scm.com/download/wi…

Global configuration

  • $ git config –global user.name “Your Name”
  • $ git config –global user.email “[email protected]

Local configuration (a project configuration)

Initialize git repository and manage Git

If you can’t see it, run the ls -a command to check it. If you can’t see it, run the ls -a command to check it

git init 
Copy the code

.git file configuration information description

  • hooks
  • info
  • objects
  • refs
  • config
  • description
  • HEAD

The three areas where Git works

  • The workspace

  • The staging area

  • Version of the area

Git add git commit workspace = = = = = = = = = = = = = = = = > the staging area = = = = = = = = = = = = = = = = > version 1. Git reset HEAD <fileName> set the file in the workspace to the red Stage The font in the version area is green. The temporary files are greenCopy the code

[git reset –hard HEAD^ /commit-id]

git log==>> > Displays the commit logs from the most recent to the most distant, from the most recent to the oldest version of Git from top to bottomlog--pretty=oneline ===>> > oneline shows [commit id] commit id of the HEAD file. Use HEAD to indicate the current version, go back to the previous version ^, and the previous version ^^.... Git reset --hard HEAD^ git reset --hard HEAD^Copy the code

[git reset –hard commit-id]

Git reset --hard commit_id Git reset --hard commit_id Git reset --hard commit_id 2) Before shuttle, use GitlogYou can view the commit history to determine which version you want to fall back to. 3) To go back to the future, check the command history with Git reflog to determine which version you want to go back to in the future. 4) If git is not added to the staging area, it will not be added to the commit. After each change, if you want to commit to the version area, first go to the temporary storage area, before going to the version area eg: commit for a file modification, git add, then directly commit, then the second change will not commit, re-add => commitCopy the code

[git rm file name]

Git add => git commt Git commit error delete retract :(replace workspace version with repository version, whether workspace is modified or deleted, can be "one-button restore".) Git checkout -- git checkout. Withdraw allCopy the code

5. Branch processing

Branches:

Note: 1) If the local branch is modified and not added to the staging area or version area, it can be switched to another branch. If there is a branch and there is no submitted file, the branch will not be merged. 4) When we create a new branch, such as dev, Git creates a new pointer called dev, which points to the same commit as master, and puts HEAD on dev, which indicates that the branch is on dev:Copy the code
5.1 Viewing Branches
Git branch Indicates the local branch. The current branch is marked with an asterisk (*). Git branch -r Indicates the remote branchCopy the code
[git checkout -b branch name]

Git checkout the git checkout command with the -b argument means create and cut

Git checkout -b branch name ==> Create a branch and switch to a new branch Branch master switches to the primary branchCopy the code
Git merge Branch name
  • Git merge branch name merge: => branch commit code, switch to primary branch, git merge branch name merge
  • Branches merge into branches
Git checkout master merges the current branch into the master branch. Git checkout master merges the current branch into the master branchCopy the code
  • Merge branch conflict resolved
Enter: :wq to exit <<<<<<<<<<<< HEAD code... = = = = = = = = = = = = = = = code > > > > > > > > > > > > > > deal with conflict, commit code, remove merge branchesCopy the code
5.4 Deleting a Branch

Note: if you are in the current branch, you cannot delete the current branch. Switch to another branch for deletion

  • Delete the local branch git branch -d ([Deleted Branch develop (was fCAaa1a).])
  • Git push origin -d

6. Conflict resolution

Git statsh to store your work
Storage: Capture the intermediate state of your working directory -- that is, the tracked files and pending changes that you have modified -- and store it in a stack of pending changes, ready to be reapplied. Scenario: It often happens that you are working on one part of a project, things are in a cluttered state, and you want to move to another branch to do some work. The problem is, you don't want to submit work halfway through, or you won't be able to get back to that point later. The solution to this problem is the git stash command.Copy the code

Git Stash storage completed, branch switch development

# On branch master
  nothing to commit, working directory clean
Copy the code

Git Stash list to look at your existing stash

Git Branch switches back and continues development,

git stash apply