preface

Git Git Git Git Git Git Git Git Git Git

The flow chart of the Git

Differences between Git and SVN

Git Git

Create a branch

Git branch user-infoCopy the code

Create a branch and switch to the currently created branch

Git checkout -b user-infoCopy the code

Switch branch

Git checkout user-infoCopy the code

Deleting a Local Branch

Note: The deleted branch can only be deleted on the parent branch

Git branch -d user-infoCopy the code

Update the list of remote branches

Careful operation

git remote update origin --prune
Copy the code

Example Delete the remote branch user-info

Careful operation

git push origin --delete user-info
Copy the code

Remove files on branches

Git rm user-info.vueCopy the code

Submits the file to the specified branch

Commit user-info to the primary branch

git push user-info master
Copy the code

Merging branches

Merge the user-info branch into the merge

Git merge user-infoCopy the code

Check the status

git status
Copy the code

See the branch

git branch
Copy the code

View all branches

git branch -a
Copy the code

Merge conflicts

1Go to the branch to merge. If you want to merge the branch to master, go to the master directory2Check whether all branches have pulled down git branch -a3Git merge Specifies the git merge branch name4Git status5If there is a conflict, resolve the conflict through the IDE;6After the conflict is resolved, commit the conflicting file to the staging area7Git commit -m git commit -m"Note"Git will automatically submit the merge result to the local repository as a comment.8Local repository code commit remote repository git push git merge branch to branchCopy the code

The add file

Add all files in the current directory to the temporary storage area

git add .
Copy the code

Add specific files

Note that the file is added under the user-info parent file. If the file is not added on the parent element, please use the path to add the corresponding file

git add user-info.vue
Copy the code

Commit code (note the commit branch)

Generally speaking, one module corresponds to one branch

git commit -m 'First version Submission'
Copy the code

View submission History

The author, time, submitted branch, etc., will be displayed. If you use git log in the Terminal of IDEA, enter wq to exit.

git log
Copy the code

Set the code tag tag

A tag is a snapshot of the version library. When releasing a version, we usually put a tag in the version library first, so that we can uniquely identify the version at the time of the tag. Whenever you take the version of a label in the future, you take the historical version of that label moment.

Add a tag to the latest commit

 git tag -a v1. 0
Copy the code

View all labels

git tag
Copy the code

Check for a concise version of the submission history

git log --oneline
Copy the code

Change the location of HEAD

Caution is often used to restore to a previous version

  1. Viewing the Version Numbergit logFind the current version number and the version number to restore
  2. useGit reset --hard 1faa6d9
  3. git pushCommit changes, an error message indicating that the version is older than the remote repository, passgit push -fForced to push

Flexible management of local development

Git rebase -i merges locally committed code into one

  1. Switch branchgit checkout master
  2. Pull the latest branch stategit pull
  3. Switch to the local branchgit checkout user-info
  4. Merger submittedgit rebase -i HEAD~2, 2 indicates the combination of two
  5. Base the current operation branch on the target branch (master)git rebase master
  6. Connect local and remote branchesrebase --continue
  7. Let’s go back to the main branchgit checkout master
  8. Merge the local branch onto the primary branchgit merge user-info
  9. Upload the local branch to the remote repositorygit push

Keep adding ~, too many, remember the commonly used good