This is the first article I participated in beginners’ introduction

Download: Download Git from taobao image and select the latest version

Npm.taobao.org/mirrors/git…

Git workflow Flowchart (Spatial Git operations)

There are four areas:

  • -Jenny: Well, I’m working in a Workspace.
  • Index/Stage: temporary storage area
  • A Repository is a Repository.
  • Remote: Remote repository
Name of the command role
“Clone” From the remote clone repository, download the remote code locally
Commit Commit commits the changes to the local repository,
Push Push commits the contents of the local repository to the remote repository
Pull The latest remote code is pulled locally to automatically merge
Fetch The latest remote code is pulled locally without merging
Checkout Create branches and switch branches
reset Roll back the code to the selected version
tag Just mark the version so it’s easy to identify

Git tools

Git is introduced

The configuration file

.gitignore is a Git configuration file that can be used in a user’s home directory (global configuration) or in a project directory (project configuration) to tell Git which files do not need to be added to version management.

/mtk/Filter the entire folder*.zip Filters all. Zip files/mtk/doC Filter a specific fileCopy the code

After filtering through the above rules, the filtered files are not pushed to the server and still exist in the local library.

!src/The folder is not filtered! *.zip does not filter all. Zip files! /mtk/do.c The file is not filteredCopy the code

The above Settings do not filter the above files

Syntax of the configuration file

To slash/The beginning indicates the directory; With an asterisk*Wildcard multiple characters; With a question mark?Wildcard single character contains a list of matches for a single character in square brackets []; In exclamation point!It does not ignore (trace) matched files or directories.Copy the code

Example configuration file

A, rule: fd1/* Ignore all contents under directory fd1; Note that both the /fd1/ directory in the root directory and /child/fd1/ subdirectory are ignored; B. Rule: /fd1/* Note: Ignore all contents of the /fd1/ directory under the root directory. C, rule: /*! .gitignore ! /fw/bin/ ! /fw/sf/ Note: Ignore all contents except the. Gitignore file and the /fw/bin/ and /fw/sf/ directories in the root directoryCopy the code

Create a folder with Git Bash

  • Right-click Git Bash Here in the root directory to go to the Bash command window.
  • The inputvim .gitignoreortouch .gitignoreCommand to open a file (no file will be created automatically);
  • Press I to switch to the editing mode, enter a rule, such as node_modules/, then press Esc to exit the editing mode, and enter :wq to save and exit.

Generate the key

Execute commands from the command line:

Ssh-keygen -t rsa -c “[email protected]” You must enter your own email address

The operation of the git

Simple code submission process

Git Clone Balabalabala.com

Open the CMD command line tool in the project folder (typically the folder containing ReadMe)

Git add. Add code to the version (add it to staging)

Git commit -m

Finally, use Git push to commit the code from the local repository to the network shared repository

Search for common functions

  • git diff --shortstat "@{0 day ago}"Look at how much code you write in a day
  • Viewing the Remote Warehousegit remote -v
  • The changed file is displayedgit status
  • Back to previous version:git reset --hard head
  • View logs:git log or git reflog
  • View the differences between workspace and staging versionsgit diff
  • Roll back to the previous versiongit reset --hard HEAD^Each one more^Roll back one more version
  • Rollback to the specified versiongit reset --hard versionVersion indicates the version number

Creating a new repository

  • git initInitialize locally (set up workspace)
  • git init [project-name]Create a new directory as a code repository
  • git clone [url]

The.git folder, which stores all version information for the current project, is usually hidden

Temporary storage area control

$ git add [file1] [file2] ...  Add the specified file to the staging area
$ git add [dir] Add the specified directory to the staging area, including subdirectories
$ git add . Add all files from the current directory to the staging area

$ git add -p
Confirm all file changes and make final changes
For multiple changes in the same file, multiple submissions can be made

$ git rm [file1] [file2] ... Delete the workspace file and place the deletion in the staging area
$ git rm --cached [file] # stop tracking the specified file, but it will remain in the workspace
$ git mv [file-original] [file-renamed] Rename the file and place the rename in the staging area
Copy the code

Local repository

$ git commit -m "message" Submit the contents of the staging area to the warehouse area
$ git commit [file1] [file2] ... -m [message] Submit the file designated for the staging area to the warehouse area
$ git commit -a Commit workspace changes since the last commit, directly to the warehouse
$ git commit -v Display all diff information when submitting

$ git commit --amend -m [message]
Use a new COMMIT instead of the previous commit
If there are no new changes to the code, the commit message is used to overwrite the last commit message

$ git commit --amend [file1] [file2] ... Rework the last commit and include new changes to the specified file
Copy the code

Branch operation

$ git branch # list all local branches
$ git branch -r List all remote branches
$ git branch -a List all local and remote branches

$ git checkout master  Switch to the master branch
$ git checkout -b [branch] Create a new branch and switch to that branch
$ git branch [branch-name] Create a new branch, but remain in the current branch

$ git branch [branch] [commit] Create a new branch that points to commit
$ git branch --track [branch] [remote-branch] Create a new branch and set up a trace relationship with the specified remote branch
$ git checkout [branch-name] Switch to the specified branch and update the workspace
$ git checkout -  # Switch to the previous branch

$ git branch --set-upstream [branch] [remote-branch] Establish a trace between an existing branch and a specified remote branch
$ git merge [branch] Merge the specified branch into the current branch
$ git cherry-pick [commit] Select a COMMIT and merge it into the current branch
$ git branch -d [branch-name] # delete branch

# delete remote branch
$ git push origin --delete [branch-name]
$ git branch -dr [remote/branch]
Copy the code

Remote function

$ git fetch [remote] Download all changes to the remote repository
$ git pull [remote] [branch] Fetch the changes from the remote repository and merge them with the local branch
$ git remote -v Display all remote repositories
$ git remote show [remote] Display information about a remote repository
$ git remote add [shortname] [url] Add a new remote repository and name it

$ git push origin master # push to master
$ git push [remote] [branch] Upload the local branch to the remote repository
$ git push [remote] --force Push current branch to remote repository forcibly, even if there is conflict
$ git push -u origin login Push the current child branch into a newly created login point

$ git push [remote] --all Push all branches to the remote repository
$ git push origin --delete [branch-name]  # delete remote branch
Copy the code

Cancel the operation

$ git checkout [file] Restore the specified file from the staging area to the workspace
$ git checkout [commit] [file] Restore the specified files of a COMMIT to the staging area and workspace
$ git checkout . Restore all files from the staging area to the workspace
$ git reset [file] Reset the specified file in the staging area, same as the last commit, but with the same workspace

$ git reset --hard Reset the staging area and workspace as the last COMMIT
$ git reset [commit] Reset the pointer to the current branch to commit, and reset the staging area, but the workspace remains the same
$ git reset --hard [commit] Reset the HEAD of the current branch to the specified COMMIT, and reset the staging area and workspace to the same as the specified COMMIT
$ git reset --keep [commit] Reset the current HEAD to specify commit, but leave the staging area and workspace unchanged

$ git revert [commit]
Create a commit to revoke the specified commit
All changes of the latter are cancelled out by the former and applied to the current branch

Uncommitted changes are temporarily removed and moved in later
$ git stash
$ git stash pop
Copy the code

TAB Settings and view

$ git tag # list all tags
$ git tag [tag] Create a new tag for the current commit
$ git tag [tag] [commit] # Create a new tag before specifying commit
$ git tag -d [tag] # delete the local tag

$ git push origin :refs/tags/[tagName] # delete remote tag
$ git show [tag] # check the tag information
$ git push [remote] [tag] # submit the specified tag
$ git push [remote] --tags # submit all tags
$ git checkout -b [branch] [tag] Create a new branch that points to a tag
Copy the code

Viewing Log Information

$ git status # show the changed file
$ git log Display the version history of the current branch
$ git log --stat Display the commit history and the files that changed each commit
$ git log -S [keyword] # Search submission history by keyword

$ git log [tag] HEAD --pretty=format:%s Display all changes after a commit, with each commit occupying one row
$ git log [tag] HEAD --grep feature All changes made after a commit must match the search criteria
$ git log --follow [file] Display the version history of a file, including file renaming
$ git whatchanged [file]

$ git log -p [file] # display every diff associated with the specified file
$ git log -5 --pretty --oneline # show the last 5 commits
$ git shortlog -sn # display all submitted users, sorted by number of submitted users
$ git blame [file] # show when and by whom the specified file was modified

$ git diff Display the difference between the staging area and the workspace
$ git diff --cached [file] Show the difference between the staging area and the last commit
$ git diff HEAD Show the difference between the workspace and the latest COMMIT of the current branch$ git diff [first-branch]... [second-branch]Display the difference between two commits

$ git diff --shortstat "@{0 day ago}" # show how many lines of code you wrote today
$ git show [commit] Display metadata and content changes for a commit
$ git show --name-only [commit] Display the files that have changed during a commit
$ git show [commit]:[filename] Display the contents of a file at the time of a commit

$ git reflog Displays the most recent commits for the current branch
Copy the code