This is the 28th day of my participation in Gwen Challenge

preface

Git is a tool with high frequency used in our daily work, and various commands are dazzling. Today, we summarize some of its basic commands here, and make an operation note.

Basic instructions

git add

Adds information about the file to be submitted to the staging area. When using Git Commit, files are committed based on the contents of the staging area.

It usually adds the current contents of an existing path as a whole, but with some options, it can also be used to add content, make only some changes to the working tree file being applied, or remove paths that no longer exist in the working tree.

Index saves a snapshot of the contents of the working tree as the next commit. Therefore, after making any changes to the working tree, and before running the git commit command, you must use the git add command to add any new or modified files to the index.

This command can be executed multiple times before submission. It only adds the contents of the specified file when the git add command is run; If you want subsequent changes to be included in the next commit, you must run Git Add again to add the new content to the index.

Add the specified file to the staging area$git addAdd all modified and deleted files to the staging area$git add -u [< path >] $git add --update# add all modified, deleted, and newly added files to the temporary storage$git add --all $git add --all $git add --allEnter a subcommand system to view all files that have been modified, deleted, but not committed$git add -i $git add --interactiveCopy the code

git branch

Operate Git branch commands.

# list all local branches. The current branch is marked with "*"
$ git branch

# list all local branches and display the last commit. The current branch is marked with an "*"
$ git branch -v

The new branch is created based on the last commit$git branchChange the branch name
# if the original branch name is not specified, the current branch is used$git branch -m $git branch -m# force change branch name$git branch -m $git branch -mDelete the specified local branch$git branch -d# Forcibly delete the specified local branch$git branch -dCopy the code

git checkout

Updates files in the working tree to match the index or the version in the specified tree. If the path is not given – Git Checkout also updates the HEAD, setting the specified branch to the current branch.

Switch to an existing branch$git checkout < branch name >Create and switch to the specified branch, keeping all commit records
"Git branch" and "git checkout$git checkout -bCreate and switch to the specified branch and delete all commit records$git checkout --orphan < branch name ># Replace local changes, new files and content already added to the staging area are not affected$git checkout < file path >Copy the code

Git checkout is one of git’s most common commands, but it’s also a dangerous one because it overwrites the workspace.

git clone

Clone the repository to the newly created directory, create a remote trace branch for each branch in the cloned repository (visible using Git branch -r), and use the repository checked out from the clone as the initial branch of the currently active branch.

Create a folder in the current directory with the same name as the repository by default and download the version to this folder
$ git clone< remote repository url ># specify a directory for the local repository
$ git clone< remote repository url > < local directory ># -b Specifies the branch to clone. The default is the master branch
$ git clone< remote repository url > -b < branch name > < local directory >Copy the code

git commit

The current contents of the index are stored in the new commit along with user and log messages describing the changes.

Commit the file in the staging area to the local repository, call the text editor and enter the description of this commit
$ git commit

Commit the file in the staging area to the local repository and add the description
$ git commit -m "< Submitted description >"

Commit all modified/deleted files to the local repository
Git add-u: git add-u: git add-u
$ git commit -a -m "< Submitted description >"

# Modify the last submitted description
$ git commit --amend
Copy the code

git config

Git parameters are used to configure Git parameters.

# Check the configuration
# --local: storage level, --global: global level, --system level
$ git config <--local | --global | --system> -l

Check the current configuration
$ git config -l

Edit the configuration file
# --local: storage level, --global: global level, --system level
$ git config <--local | --global | --system> -e

Add a configuration item
# --local: storage level, --global: global level, --system level
$ git config <--local | --global | --system> --add <name> <value>

Get the configuration item
$ git config <--local | --global | --system> --get <name>

Delete the configuration item
$ git config <--local | --global | --system> --unset <name>

Configure the user information in the commit record$git config --global user.name $git config --global user.email# Change Git cache size
If the submitted content is large, the default cache is small, and the submission fails
# Cache size unit: B, e.g. 524288000 (500MB)$git config --global http.postBufferGit diff /git diff /git diff /git diff
$ git config --global color.ui true

The default cache time is 15 minutes
$ git config --global credential.helper cache

Set the password cache time
# Cache time in seconds
$ git config --global credential.helper 'cache --timeout=< cache time >'

# Configure long-term storage password
$ git config --global credential.helper store
Copy the code

Git has three configuration files:

  1. Warehouse level configuration files: in the warehouse.git/.gitconfigThis configuration file is valid only for the repository in which it is located.
  2. Global profile: Mac system in~/.gitconfig, Windows system inC:\Users\< user name >\.gitconfig.
  3. System-level configuration files: in the Git installation directory (on Mac systems, the installation directory is in/usr/local/git)etcIn foldergitconfig.

git diff

Used to show changes between commits and work trees, etc.

This command compares the difference between the current file in the working directory and the snapshot of the staging area, that is, changes that have not been provisionally stored after modification.

Compare the current file with files in the staging area to show changes that have not been temporarily stored
$ git diff

Compare the file in the staging area with the last time it was committed
$ git diff --cached
$ git diff --staged

Compare the difference between the current file and the last time it was committed
$ git diff HEAD

# view changes since the specified version
$ git diff <commit ID>

# Compare the differences between two branches$git diff < branch name >See what changes have been made to the two branches since they split$git diff < branch name >... < branch name >Copy the code

git fetch

Get the latest version from the remote repository to the local TMP branch.

Fetch the latest versions of all branches of the remote repository$git fetch < remote repository alias >Fetch the latest version of the specified branch of the remote repository back to the local directory$git fetch < remote host name > >Copy the code

git init

Initialize the project directory. After initialization, a.git directory will appear under the current directory.

Create a.git folder in the current directory
$ git init
Copy the code

git log

Displays committed records.

Print all submission records
$ git log

Print the record from the first commit to the specified commit
$ git log <commit ID>

Print the specified number of most recently committed records
$ git log-< specified quantity >Copy the code

git merge

Used to add (merge) two or more development histories together.

# merge the specified branch into the current branch and automatically commit the new branch$git merge# merge the specified branch into the current branch, no new commit$git merge --no-commitCopy the code

git mv

Rename a file or folder.

Rename the specified file or folder$git mv $git mvCopy the code

git pull

Get the latest version from the remote repository and merge it locally. Git fetch is performed first, followed by git merge, which merges the HEAD of the acquired branch into the current branch.

Get the latest version from the remote repository.
$ git pull
Copy the code

git push

Push a commit from a local repository to a remote repository.

Push the branch of the local repository to the specified branch of the remote repository$git push < remote repository alias > < local branch name >:< remote branch name >Drop the branch of the specified remote repository$git push -- $git push -- $git push -- $git pushCopy the code

git remote

Operate remote libraries.

# list remote repositories that already exist
$ git remote

List the URL address after the alias
$ git remote -v
$ git remote --verbose

Add remote repository$git remote add $git remote addChange the alias of the remote repositoryGit remote rename $git remote rename# delete remote repository with specified name$git remote removeChange the URL of the remote repositoryGit remote set $git remote set $git remote setCopy the code

git reset

Restore the commit record.

Reset the staging area, but the files are not affected
Git add = git add = git add = git add = git add
# if no commit ID is specified, the current HEAD will default$git reset --mixed [< file path >]# change the direction of the HEAD, undo to the specified commit record, file is not modified
$ git reset <commit ID>
$ git reset --mixed <commit ID>

# change the direction of the HEAD, undo to the specified commit record, file is not modified
Git add = "git reset --mixed"
$ git reset --soft <commit ID>

# change the direction of HEAD, undo to the specified commit record, and modify the file
$ git reset --hard <commit ID>
Copy the code

git revert

A new commit is generated to undo a commit, and all commits prior to this commit are retained.

Make a new commit to undo a commit
$ git revert <commit ID>
Copy the code

git rm

Delete files or folders.

Remove trace specified files and delete them from the local repository folder$git rm# remove trace specified folder and delete it from local repository folder$git rm -r# remove trace specified file, keep the file in the local repository folder
$ git rm --cached
Copy the code

git status

Used to display the status of working directories and staging areas. Using this command you can see which changes are temporarily saved, which are not, and which files are not tracked by Git.

Check the status of the local repository
$ git status
Copy the code

Git status does not display information that has been committed to the project history.

To view project history information, use the Git log.

git tag

Commands to manipulate labels.

Print all labels
$ git tag

# Add a lightweight tag that points to a reference to the commit object and can specify the previous commit record$git tag [<commit ID>]Add a note tag with description information to specify the previous submission record$git tag -a < tag name > -m < tag description > [<commit ID>]Switch to the specified TAB
$ git checkout <标签名称>

# Check the tag information$git show# delete the specified tag$git tag -dCommit the specified tag to the remote repository$git push < remote repository alias > < tag name >Commit all locally owned tags to the remote repository$git push < alias for remote repository > - tagsCopy the code

~

Thanks for reading!

~

Learn interesting knowledge, meet interesting friends, shape interesting soul!

I am the author of programming Samadhi, yi Wang, my public account is “programming Samadhi”, welcome to pay attention to, I hope you can give me more advice!

You come, with expectations, I have ink to welcome! You return, no matter gain or loss, only to yu Yun give each other!

Knowledge and skills should be paid equal attention to, internal force and external power should be repaired simultaneously, theory and practice should grasp both hands, both hands should be hard!