The flow chart of the Git

  • Workspace: the workspace
  • Index / Stage: the staging area
  • Repository: Warehouse area (or local warehouse)
  • Remote: Remote warehouse

Configure Git

$git config --global user.name "username" $git config --global user.email "git account alias.co checkout $ git config --global alias.ss status $ git config --global alias.cm commit $ git config --global Alias. br branch $git config --global alias.rg reflog # $git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit alias.xxx $ git config --global --unset user.xxxCopy the code

Checking Git Information

Gitconfig # $cat. Git /config # $git ls-files # Check local git command history $git reflog # to see all the git command $git # -- help - a view the current HEAD toward $the git/HEAD # git D scroll down one line F down page page up Q B $git log --oneline --grep=" keyword "--graph --all --author "username" -- reverse-num -p --before= 1 day/1 Week /1 "2019-06-06" --after= "2019-06-06" --stat --abbrev-commit --pretty=format:" XXX "# oneline - # graph -> Graph -> graph -> graph -> graph # reverse -> commit Reverse the commit sequence # before -> find the commit before the specified time (e.g. 1 day /1 week) # num -> git log-10 # stat -> Display file modification statistics for each update. # abbrev-commit -> Display only the first few characters of SHA-1, not all 40 characters!! # pretty=format:" XXX "-> Can be customized to display the record format!! # p -> Display the differences introduced by each commit (output in patch format)!!Copy the code

git reflog

  • It shows oneHEADPoints to a list of times that changed. Before you switch branches, usegit commitSubmit, and usegit resetWhen you revoke the COMMIT,HEADThe direction will change, but as you proceedgit checkout -- <filename>Revocation orgit stashWhen you do things like store files,HEADIt doesn’t change, these changes were never committed, soreflogIt doesn’t help us recover them.
  • git reflogNot forever. Git cleans up “unused” objects on a regular basis. Don’t expect a commit from months ago to still be there.

Git log dot plot

  • A branch in Git is a pointer, and creating a branch is a pointer based on the current pointer
  • To switch to a branch is to point a HEAD to a branch.
  • To switch to a COMMIT is to point HEAD to a commit

Symbol interpretation:

* a commit | said branch bifurcate \ indicated into | / forward/said said the new branchCopy the code

Git Git

$git add. # Commit to local repository $git commit -m $git commit -u origin branchName $git commit -u origin branchName $git pull origin branchName $git merge branchName $git branch # $git branch -a # Switch branches $git checkout branchName # Temporarily save workspace file changes to the stack $git stash # Pull out files previously saved to the stack $git branch - A # Switch branches $git checkout branchName  git stash popCopy the code

Git common command description

add

Adds files from the workspace to the staging area

$git add [file1] [file2]... $git add. $git add. $git rm [file1] [file2]... # stop tracking specified files $git mv [file-original] [file-renamed] # git 2.0: $git add. $gti add -u $git add. Equivalent to $git add -aCopy the code
  • git add .The object of the action is all file changes in the current directory, “.” indicates the current directory. Will monitor the workspace state tree, using it will put the workspaceAll changes submittedTo the staging area, including file content modification (modified) and new documents (new), butDeleted files are not included.
  • git add -uThe object of action is the file changes that have been tracked throughout the workspace, regardless of the current directory. Only monitorFiles that have been added(i.e.tracked file), which commits modified files (including file deletions) to the staging area.git add -uNo new documents will be submitted (untracked file). (git add --updateThe abbreviation of)
  • git add -AThe object of action is changes to all files in the “entire workspace”, regardless of the current directory. Is a combination of the above two functions (git add --all“).

status

$git status = $git statusCopy the code

commit

$git commit -m $git commit -m $git commit -m $git commit --no -- verify $git commit -n $git commit -- amend-m $git commit -- amend-m The editor does not pop up the last committed information $git commit --amend --no-editCopy the code
  • git commit --amendYou can modify the contents of the last submitted file or the description of the last submitted file. I’ll use a new onecommitUpdate and replace the last committedcommit. If there’s anything in the staging area, this newcommitAny changes will be matched with the previous onecommitThe content is combined. If there is no content in the staging area, then this operation will only take the last onecommitThe message is rewritten.Never fix a commit that has already been pushed to the public repository

push & pull

  • The branch push order is written as < source >:< destination >
If the remote repository does not have this branch, a new branch with the same name will be created. $git push origin branchname $git push origin branchname This is equivalent to pushing an empty local branch to the remote branch. $git push origin = $git push origin = $git push origin = $git push origin $git push $git push $git push $git push $git pull pull origin branchname # $git pull origin branchname # Git merge origin branchName $git merge origin/branchName You are required to do git pull locally to merge differences, # and then push to a remote host. At this moment, if you must push, you can use the -- force option # (avoid) $git push -- force origin | git push - f originCopy the code

branch

# to check the local branch $git branch | git branch - l # to check the remote branch $git branch - r # view all branch (branch), local branch + remote # $git branch - a view all branches and to bring the latest submitted information $ $git branch -v $git branch -v $git branch -v $git branch branchname = $git branch branchname = $git branch branchname $git checkout branchname $git checkout branchname $git checkout -b aaa $git checkout -b aaa $git checkout --orphan emptyBranchName $git rm -rf. # $git brnach -d branchname $git branch -d branchname $git branch -m branchname = $git branch -m branchname = $git branch -m branchname = $git branch -m branchnameCopy the code

Merge Three common merge methods

$git merge --no-ff $git merge --squashCopy the code

  • fast-forward: Adds the merged branch’s commit history to the current branch’s commit history (You need to understand when a fast merge happens, not every merge happens fast merge, okay);
  • --no-ff:A new commit is generatedTo make the commit history of the current branch less messy;
  • --squash:No new commits are generated, will directly store the content submitted by the merged branches to the workspace and staging area, and the developer will commit it manually. In this way, the current branch will end up with only one more commit record, and the merged branch’s commit history will not be mixed

rebase

www.liaoxuefeng.com/wiki/896043…

Git-scm.com/book/zh/v2/…

www.jianshu.com/p/4a8f4af4e…

Juejin. Cn/post / 684490…

stash

  • The ability to save all uncommitted changes to the stack for subsequent restoration of the current workspace contents
  • If the document is not submittedStaging area (use git add. to track new files)Is displayed when using the commandNo local changes to saveCannot save changes to the stack

Usage scenario: When you are given an urgent bug fix task, it is common to create a new bug branch to fix it, then merge it, then delete it. However, if you are currently developing a feature and cannot complete it in a short period of time, you can first put the contents of the current workspace under git Stash and then fix the bugs. After fixing the bugs, you can restore the previous work content with git Stash pop.

Save all uncommitted changes to the stack with $git stash $git stash list $git Stash list on Windows and PowerShell Need double quotation marks # after resuming, Stash pop "stash@{index}" # delete stash record $git $git stash show $git stash show "stash@{index}" # $git stash show -p "stash@{index}"Copy the code

diff

$git diff $git diff $git diff $git diff --stat # You modify a file but do not commit it to the staging area, there will be a comparison # 2 once committed to the staging area, there will be no comparison (because the staging area has been updated). If you create a new file and don't commit it to the staging area, $git diff --cached/--staged # Git diff --cached/--staged # Git diff BranchName # Git diff branchname # Git diff branchname # Git diff HEAD # $git diff branchName $git diff branchname $git diff branchname... $git diff branchname $git diff origin/branchname... $git diff origin/branchname $git diff origin/branchname... $git diff commit1.. commit2Copy the code

remote

$git remote rm projectname $git remote rm projectname $git remote rm projectname $git remote rm projectname  remote set-url origin <newurl>Copy the code

tag

Often used to release versions

www.liaoxuefeng.com/wiki/896043…

$git tag v0.9 f52C633 $git tag v0.9 f52C633 $git tag -a v0.1 -m "Version 0.1 released" # git tags are not listed in chronological order, but alphabetically. $git tag # $git tag # $git tag # $git tag # $git tag # Tags created are only stored locally and are not automatically pushed to remote locations. # Therefore, mislabeled tags can be safely deleted locally. $git push origin :refs/tags/<tag > $git push origin :refs/tags/<tag >Copy the code

Delete the file

$git rm --cached filename $git rm --cached filenameCopy the code

If you uploaded a file to the remote repository before configuring the.gitignore file and want to delete it from the remote repository, it is useless to configure the.gitignore file because it has already been traced, but you do not want to delete the file locally and then recommit it to the remote repository. You can use the git rm –cached filename command to untrace the file, so that the next time git commits the file, it will not commit again and will be deleted from the remote repository

Version switch & Reset & Undo

  • Checkout can undo workspace files, and reset can undo workspace/staging files
  • Reset and checkout can work with commit or files, while Revert can only work with COMMIT

Checkout,

$git checkout <filename> $git checkout <filename> If you have committed the modified file to the repository, $git checkout HEAD $git checkout HEAD -- filename $git checkout HEAD $git checkout HEAD $git checkout HEAD $git checkout < branch you are currently using > # switch to the specified commit version $git checkout <commit_id checkout <tag>Copy the code
  • In normal phases of development, HEAD points to master or other local branches, but when you use git checkout

    to switch to a specific commit, HEAD no longer points to a branch — it points directly to a commit. The HEAD is going to be in a detached state.
  • After switching to a commit, you can view the file, compile the project, run tests, and even edit the file without worrying about whether it affects the current state of the project. Everything you do is not stored in the repository of the main stack. Use this when you want to get back to the main line of developmentgit checkout branchNameReturn to the original state of the project (You will be prompted to create a new branch to keep the changes).
  • Even if you switch to a version of the commit, make changes to it, and accidentally commit to the staging area, as soon as you switch back to the branch, you’ll still be back to the original state of the project. (Note: Changes you make, if committed, will be saved to that version. After switching branches, you will be prompted to create a new branch to hold your changes. If you’ve just solved a bug, create a temporary branch and merge it with your local developer main branch, then delete the temporary branch).
  • I usually use checkout to roll back the version, check the history code, and test the bugs

Reset,

Git reset [- hard | soft | mixed | merge | keep] [< commit > or HEAD] : Resets the current branch to the specified

or HEAD (by default, if the specified < COMMIT > is not displayed, the default is HEAD, which is the last commit), with the possibility of updating the index and working directory according to [mode]. The mode can be hard, soft, mixed, merged, or keep.

# Undo a specific file from the staging area without changing the workspace. $git reset <fileName> # resets the last commit in the staging area. $git reset = $git reset HEAD = $git reset HEAD = $git reset $git reset --hard HEAD^ # set the pointer to the current branch to commit (commit will be removed) and reset the staging area. $git reset <commit> # equivalent to $git reset --mixed <commit> # $git reset --hard <commit> $git reset --hard <commit>Copy the code
  • git resetThere are many ways to use it. It can be used to remove commit snapshots, although it is commonly used to undo staging and workspace modifications. In either case, it should only be used for local modifications — you should never reset snapshots shared with other developers.
  • When you use reset to roll back to a version, subsequent versions of the previous version will be garbage deleted in the next Git commit.
  • When you go back to an old version and use git log to check the commit record, you will find that the previous new version record is missing. What if the next day, you want to go back to the new version? What if you cannot find the new version of commit_id?

We can usegit reflogLook at the history command so you can see the commit_id of the previous new version, and thengit reset --hard commit_idYou can go back to the new version of the code

  • While you can use Git reflog to view your local history and revert to the previous version of the code, you can’t get your history commands on other computers, so it’s not secure. If your computer suddenly crashes, you can’t go back to a future version.

Revert,

$git Revert HEAD = $git Revert HEAD = $git Revert HEAD = $git Revert HEAD = $git Revert $git revert HEAD~num # $git revert <commit_id> # $git revert HEAD~num # $Git revert <commit_id> --no-editCopy the code

Using the git revert command, you can undo a snapshot that has been committed (unlike reset to a specific version). Instead of removing the commit from the project history, it keeps Git from losing the project history by adding a new commit with the changes undone to the end of the commit record.

Undo (revert) should be used when you want to remove a commit from the project’s history. For example, if you are tracking a bug and you find out that it was caused by a commit, undo is useful.

Undo is designed to be a safe way to undo public submissions, and reset is designed to reset local changes.

Because the purpose of the two commands is different, they are implemented differently: reset completely removes a bunch of changes, undo preserves the original changes, and undo is implemented with a new commit. Never use Git reset to roll back commits that have been pushed to the public repository. It only works for rolling back local changes (never committed to the public repository). If you need to fix a public commit, use Git Revert.

After publishing a commit, you must assume that other developers will rely on it. Removing a commit on which other team members continue to work can cause serious problems in collaboration. When they try to synchronize with your warehouse, they find that part of the project’s history has suddenly disappeared. If you add a new commit after a reset, Git will think that your local history has been forked with Origin/Master, and synchronizing your repository with a merge commit will confuse your colleagues.

cherry-pick

Apply the specified commit commit to the current branch (which can be used to recover accidentally undone (revert/reset) commits)

$ git cherry-pick <commit_id> $ git cherry-pick <commit_id> <commit_id> $ git cherry-pick <commit_id>^.. <commit_id>Copy the code

git bisect

  • Quickly find buggy commits
  • The idea is simply to narrow down the history of code submissions in a dichotomy. The idea of “dichotomy” is to split the code history into two parts, determine whether the problem is in the first or the second half, and continue this process until it Narrows down to a single code commit.
# "end" is the most recent submission, $git bisect start [commit_id] $git bisect start HEAD commit_id # $git bisect reset = $git bisect reset = $git bisect reset = $git bisect resetCopy the code

Git subModule Submodule

We often encounter situations where a project at work needs to include and use another project. Maybe it’s a third-party library, or one you developed independently for multiple parent projects. Here’s the problem: you want to treat them as two separate projects, but at the same time you want to use the other in one project. If you copy code from another project into your own project, any custom changes you make will make it difficult to incorporate upstream changes. Git solves this problem with submodules that allow you to use one Git repository as a subdirectory of another. It allows you to clone another repository into your own project while keeping the commit independent.

Git submodule add [URL] [path] # clone the main project with the submodule. The default directory contains the subproject, Git submodule update # Is equivalent to git submodule init Git submodule update git submodule update Git Clone --recurse-submodules [URL]Copy the code

Two ways to create a Git project

1. Create a local Git project and associate it with the remote repository

$Git remote add <name> <git-repo-url https://github.com/xxxxxxCopy the code

2. Clone remote warehouse

$git clone < git-rebo-url > $git clone < git-rebo-url > $git clone <git-repo-url> <project-name>Copy the code

Git branch management specification

Blog.csdn.net/LitongZero/…

Juejin. Cn/post / 684490…

  • In actual development, one branch per person (Personal opinion: Unless it is a large project with a large number of developers involved, the feature branch can be adopted. Otherwise, in general projects, one branch for each developer is sufficient). There is also a Develop, a test, and a Release pre-release branch.
    • Every day developers need to pull/submit branches of the latest code;
    • Test: Test branch, which is released to the test environment after developers have developed and passed the self-test.
    • Release: pre-release branch, after the test environment passes the test, the code of the test branch will be released to the branch of the pre-release environment (this depends on whether the company supports the pre-release environment, otherwise you can not use this branch);
    • Master: online branch. After passing the pre-release environment test, the operation/test will publish the branch code to the online environment.
  • General process:
    • Developers need to pull/submit the latest code to the Develop branch every day;
    • After the developer finishes the development, the integration test is started. After the test is done correctly, it is submitted to the Test branch and released to the test environment for testing by the tester.
    • After the test environment passes, it is released to the release branch for pre-release environment testing.
    • After the pre-release environment passes, publish it to the master branch and tag it.
    • If there is a bug in the online branch, the developer should create a new bug branch based on the pre-release branch (if there is no pre-release environment, use the master branch) to temporarily solve the bug and apply for merging into the pre-release branch after processing the bug. This has the advantage of not affecting the functionality in development.

What the pre-release environment does: The pre-release environment is the last test before the official release. Because in a few cases, even if the pre-release passes, there is no guarantee that the formal production environment will be 100% trouble-free; The configuration of pre-release environment, database and so on are the same as online; For some companies, the pre-release environment database is an on-line environment, while for others, the pre-release environment is a separate database. If there is no pre-release environment, if there is a problem with developing merged code, the problem will be directly published online, increasing the maintenance cost.

Git hooks

4.1 the pre – commit

  • pre-commitYou do things like code packaging, code detection, called hooks, before you submit your code.
  • A function (callback) is executed before commit. After this function completes successfully, commit continues, but prevents commit after failure
  • Under.git->hooks-> there is a pre-commit. Sample *, which contains the default function (script) samples

4.2 installation of pre – commit

npm install pre-commit --save-dev
Copy the code

4.3 Configuration Scripts

If not in the.git->hooksDirectory generationpre-commitFiles are created manuallynode ./node_modules/pre-commit/install.js

"scripts": {
    "build": "tsc"."eslint": "eslint src --ext .ts"."eslint:fix": "eslint src --ext .ts --fix"
  },
 // Run the eslint command in scripts before committing the code
  "pre-commit": [
    "eslint"
  ]
Copy the code

4.4 Skip pre-commit and continue to commit the code

#Skip the verification
$ git commit --no-verify
$ git commit -n
Copy the code

More hooks: git-scm.com/book/zh/v2/…

Q&A

If you accidentally delete someone else’s remote branch, it is useless to try to pull someone else’s branch again. It will say “already up”

At this point, you can roll back the code and pull again.

2. I have had experience in the past: the front and back end and the client side of the code are stored in a Git repository, under the root directory of the new project directory. You can use git to commit code in your own project directory and configure.gitignore files in your own project directory instead of in the root directory

3, Fatal: refusing to merge suggested histories

After Git 2.9.2, it is not possible to merge branches that do not have the same node (branches have never been pulled and merged with each other since the repository was created). If you need to merge branches of two different nodes, do as follows:

$ git pull origin branchName --allow-unrelated-histories
$ git merge branchName --allow-unrelated-histories
Copy the code

This function is to let you do not upload the warehouse wrong, if you will add this code, then you are sure to upload. With older versions of Git, it’s very easy to upload the wrong code, and now you can see that if you upload something different, you need to add code to upload. Under normal circumstances, are the first to establish the warehouse, and then cut multiple branches, branches to pull the content of the main branch, and then their own development, if the establishment of the warehouse, each branch has no area to pull the code of the main branch, after the branches want to merge will report an error.

4. There is a problem with merging branches and you want to unmerge the status

error: merge is not possible because you have unmerged files.
hint: Fix them up in the work tree, and then use 'git add/rm <file>'
hint: as appropriate to mark resolution and make a commit.
fatal: Exiting because of an unresolved conflict.
Copy the code

When a remote branch conflicts with a local branch, Git stays in merge state. If you don’t resolve all the conflicts, Git stays in merge state and you can’t commit any more code. The commit can only continue after the merge state has been unstuck. You are advised to back up the command before executing it. Changes made locally may be overwritten by remote branches.

$git merge --abortCopy the code

5. Accidentally uploaded some files to a remote Git repository/wanted to delete files from the remote repository

$git rm --cached filename $git rm --cached filenameCopy the code

If you uploaded a file to the remote repository before configuring the.gitignore file and want to delete it from the remote repository, it is useless to configure the.gitignore file because it has already been traced, but you do not want to delete the file locally and then recommit it to the remote repository. You can use the git rm –cached filename command to untrace the file, so that the next time git commits the file, it will not commit again and will be deleted from the remote repository

6. Upload the locally created project to the newly created remote repository

There was no association before, that is, the clone remote project was not sent to the local site and then the project was started. Instead, a new project was created locally and then uploaded to the remote warehouse.

Git remote add origin $git remote add origin $git remote add origin $git push -u origin master # $git push = $git pushCopy the code

The HEAD pointer can point to either a branch (the default is the current branch) or a snapshot. The state of the HEAD pointer when pointing to a snapshot is called a detached state.

Principles for creating and merging branches

www.liaoxuefeng.com/wiki/896043…

9. Enter your username and password every git push

  • Step 1: Generate the public key
ssh-keygen -t rsa -C "[email protected]" # Generating public/private rsa key pair... 3 press Enter to generate the SSH keyCopy the code
  • Step 2: View the generated public key
cat ~/.ssh/id_rsa.pub
Copy the code
  • Step3 copy the generated public key and add it to the git server

Test whether SSH connection is successful

$ ssh -T [email protected]
Copy the code
  • Step4: clone the remote repository using SSH or if it has been cloned to the local using HTTPS, then reset the remote repository

Using SSH

$ git remote set-url origin [email protected]:xxx/xxx.git
Copy the code
  • Step5: create a file storage user name and password

The directory is usually C:\users\Administrator, or you can create your own system username directory with the file name.git-credentials. Since you are not allowed to create a file that begins with a “.” directly in Windows, you create the file on the command line.

$ touch .git-credentials
$ echo "http://{username}:{password}@github.com" >> ~/.git-credentials 
$ git config --global credential.helper store
Copy the code

Git does not allow you to submit empty folders

You can add a.gitkeep file to the current directory

11, sometimes copy over the file, usegit add .Unable to file trace, can usegit add -AThat is, before each submissiongit statusThe reason why

12,Configure multiple Git accounts on the same computer

Github.com/jawil/notes…

13, Another Git process seems to be running in this repository, LLDB.

The reason is that some locked resources are not released due to a crash in the use of Git.

Solution: Go to the.git file in the project folder (display hidden folder or rm. Git /index.lock) and delete the index.lock file.

Git commit-am “XXX” sometimes fails to commit all changes

Git commit-am “XXX” only adds a file tracked to the staging area and commits, whereas adding a file tracked to Git management uses the git add command, which tracks the new file. After creating a file, IDEA will prompt you to add it to Git management. Then idea defaults to new file tracked.)

Git merge –no-ff

  • Fast -forward merges are disabled and a new commit is generated

From the merged code, the result is the same, except that no-ff causes Git to generate a new commit object. Why? Generally, we regard master as the main branch, where stable codes are stored and submission frequency is low. However, feature is used for feature development, and there are many fragmented submissions on it. Fast-forward merging will mix the submission history of feature into master. Mess with the master’s commit history. So if you don’t care about submitting history, and if you don’t care about the master being clean, then — no-FF doesn’t really work.

Segmentfault.com/q/101000000…

Git rebase git rebase git rebase git rebase

Juejin. Cn/post / 684490…

Blog.csdn.net/liuxiaoheng…

Segmentfault.com/a/119000001…

Segmentfault.com/a/119000001…

Git log cannot display Chinese characters

$git config --global core.pager more $git config --global core.pager moreCopy the code

www.zhihu.com/question/57…

www.playpi.org/2019031901….

Git merge -m “XXX

  • The default is Merge Branch branchName

19. Git pull pulls all remote branch code into the local mirror repository

When you want to merge someone else’s branches:

  • Merge BranchName if you already have someone else’s branch in your local repository (switching directly to someone else’s branch generates a branch locally), you can use merge Branchname.
  • Merge Origin/BranchName if your local repository does not have someone else’s branch, merge Origin/Branchname

20, Git branch -r/-a/-l specifies a branch from the local repository. If the local repository does not pull the code from the remote repository, you cannot view the branch from the remote repository

21. Git Stash Stores untracked files

  • If we create a new file and it doesn’t workgit add .Trace the files, thengit stashIt can’t be stored
$ git stash -u
Copy the code

22. How to create a PR project on Github

Segmentfault.com/a/119000002…

Git push cannot commit code

Possible errors:

Git configuration $cat. git/configCopy the code
  • Check whether the repository URL set in the.git/config file of the local project is the same as the link used on Github.git pushThere are two types of data protocols:sshhttps. If they are inconsistent, you need to switchurlAddress.

24, Git input error user name and password, subsequent git operations always error

Remote: Coding prompt: Authentication failed. Remote: Authentication failed. Please confirm that you have entered the correct account password. fatal: Authentication failed for 'https://e.coding.net/xxx.git/'Copy the code

Go to the credentials manager in the control panel, select Windows credentials, locate git credentials, click Edit, and enter the correct username and password for github to use.

Lint-passage failed

Maybe your project name path contains a Chinese name and needs to be replaced with an English name

26. Check the git installation directory

  • Mac:Enter it on the command linewhich gitThe git installation location will be displayed
  • Windows:Open CMD and typewhere gitThe git installation path will be displayed

27,Git uses vim to open, modify, and save files

28,Windows10 cannot edit vimrc

29,Windows Git Bash VIM open file Chinese garbled

30, How to modify old commit messages/how to combine multiple commit messages into one commit/ How to combine multiple spaced commit messages into one commit/

git rebase -i
Copy the code

31, If two people have modified a file, one is to rename the file, the other is to modify the file content, then there will be a conflict? Git is smart enough to automatically merge these changes

If two people rename the same file, there will be a conflict that Git doesn’t handle automatically and requires the developer to resolve

Git failed to revert with error: Commit faulty merge is a merge but no-m option was given. option `mainline’ expects a number greater than zero

Segmentfault.com/a/119000001…

www.jianshu.com/p/3719dae37…

git revert -m 1 
Copy the code

33,Git creates an empty branch

To create a branch in Git, you must have a parent node, which means you must create a branch on top of an existing branch. You cannot create an empty branch if the project has been in progress for a while. But sometimes you just need to create a blank branch.

$ git checkout --orphan emptyBranchName
Copy the code

This command generates a branch called emptyBranch that contains all the files of the parent branch. But the new branch does not point to any previous commits, because it has no history. If you commit the current content, this commit will be the first commit of the branch.

If you want an empty branch, you need to delete all the current content with git

$git rm -rf.Copy the code

34. How do I clear all commits for a branch

Delete the branch first, and then create an empty branch (the branch name is the deleted branch name) ~~

35,How do I quickly find buggy Commits

Recommended reading

Do you really understand the React lifecycle

React Hooks 【 nearly 1W words 】+ project combat

React SSR: + 2 projects

Cookie, Session, Token, JWT

TS FAQ sorting (more than 60, continuously updated ing)

reference

Git Book

Pro Git (Chinese version)

git-recipes

How to use Git gracefully

How to use Git submodule development in a large project

Github API Call (v3)

www.jianshu.com/p/a0c7d0482…

Developer.github.com/v3/guides/g…