preface

Git, as an advanced version management tool, has been widely used in a large number of projects. Recently, I found a very good git learning website. Although it is relatively basic, the visual interface can help newcomers quickly understand the function of each git instruction, and at the same time, it can also make up for the missing to a certain extent. Web site address: learngitbranching.js.org/ and this article also recorded the git command and use of some commonly used techniques

Git commands

The new warehouse

Git init [projectName] git clone [url] git clone [url]

configuration

If you are new to Git, you will need to configure your email address and username. Git conifg [–global] user.name “[username]” git conifg [–global] user.email “[email]” You can view the current git configuration Git config -e [–global] git config -e [–global]

Add and delete files

Here’s a quick introduction to the concept of workspace and staging in Git

  • A workspace can simply be defined as changes you make to your current repository that Git can detect but not prepare for the next commit. You need the user to add it to the staging area.
  • The staging area can be simply interpreted as the files that will be committed on the next execution of the commit.
  • The entire workflow is: you modify a file -> it becomes a workspace file -> you add the file to the staging area -> Commit the staging file and the file is committed

Git add [file1] [file2]… Git add [dir] Add all files in the current directory to the staging area. Git rm [file1] [file2]… Git rm –cached [file] rename the file and place it in the staging area git mv [origin-name] [target-name]

Submit code

Git commit [file1] [file2] git commit [file1] [file2]… -m “message” commits the workspace directly to the repository since the last commit (skipping the staging area). Git commit — amend-m [message]

Branch operation

Git branch is a very powerful function, new, delete, switch branches very fast, you can use more

Git branch -r Git branch -a Create a new branch and leave it at the current branch. Git branch [branch-name] Create a new branch. Git checkout -b [branch-name] -b [branch-name] -b [branch-name] -b Git branch [branch-name] [commit] Create a branch. Git branch –track [branch-name] [remote-branch] Switch branch git checkout [branch-name] Merge the specified branch to the current branch git merge Git rebase [branch-name] interactive rebase git rebase [branch] -i Selects a commit (on any branch), Git cherry-pick [commit] Delete branch git branch -d [branch-name] Delete remote branch git branch -dr [origin/branch] git push origin –delete [branch-name]

The label

A tag can be used to add a traceable tag to a commit, which is branch independent, does not change, and can be traced in any case. It is often possible to label a significant commit (such as a release)

Git tag add a new tag to the current commit git tag [tag-name] Add a new tag to the specified commit git tag [tag-name] [commit] Delete a local tag git tag -d Git push origin :refs/tags/[tag-name] Git show [tag-name] Delete a tag from a remote repository. Git push [remote] git push [remote] git push [remote] Creating a branch git branch [branch-name] [tag-name]

Check the information

Git status displays the version history of the current branch. Git log –stat displays every change to the specified file. Git log -p [file] displays every change to the specified file Git diff –cached [file] Git diff –cached [file] Git diff HEAD git diff shows how many lines of code you wrote today Git reflog –shortstat “@{0 day ago}” displays the most recent commits of the branch

Remote synchronization

Git fetch [remote] git fetch [remote] git fetch [remote] git fetch [remote] Git remote add [name] [url] Git pull [remote] [branch] Upload the local branch to the remote repository git pull [remote] [branch] push the current branch to the remote repository Git push [remote] –force Push all branches to the remote repository

undo

Git checkout [file] git checkout [commit] [file] Git checkout Git reset [file] Resets the workspace and the staging area, the same as the last commit. Git reset –hard resets the pointer of the current branch to the specified commit, and resets the staging area, Git reset [commit] Reset the HEAD of the current branch to the specified commit, reset both the staging area and the workspace to the specified commit. Git reset –hard [commit] Create a new commit. Git Revert [commit] Temporarily removes uncommitted changes and later moves to git Stash git Stash pop

Git reset contains –soft –hard –mixed parameters. The default is –mixed. Git reset

The HEAD of mobile

HEAD is a very important concept in Git, so I’ll separate it out here. HEAD is a pointer in Git that marks the current location. Git knows where you are because of HEAD.

Normally, the HEAD points to the current branch (the most recent commit), but sometimes we can have the HEAD point to a specific commit. This is also called splitting the HEAD. For example, if you do not specify commit when creating a branch, the branch will be created at the current HEAD location.

Git checkout [commit-id] Git checkout [commit-id] Git checkout [commit-id] git checkout [commit-id] Git checkout HEAD~3 git checkout HEAD~ 2 git checkout HEAD~3 git checkout master~5

Further information can be found on more uses of HEAD

Afterword.

The above are just some of the common instructions for git entry, after proficiency can deal with the general use of Git scenarios. Here is still recommended learngitbranching.js.org/ for actual operation time, believe that the use of git are of great help.