Git Commands

Start using Git

  • Setting a User Name
git config --global user.name "Your Name"
Copy the code
  • Set up your email
git config --global user.email "[email protected]"
Copy the code
  • prompt
If you use HTTPS, you need to enter your password every time. You can enter your password by following the following Settings to avoid the trouble of manually entering your password and enjoy the fast setting brought by HTTPS. Remember your password (15 minutes by default) : Git config --global credential. Helper cache git config --global credential. Helper cache Git config --global credential.helper store git config --global credential.helper store git config --global credential.helper storeCopy the code
  • Create repository (current directory)

git init

  • Add files

Git add.

Note: If you modify a file after adding it, add it again before committing

  • submit

Git commit -m

  • Check the status

git status

  • To view changes

Git diff

View changes in a single file

  • View Historical commits

Git log –pretty=oneline A single commit is displayed as a single line git

  • View History Command

git reflog

Version control

  • Version back

Git reset –hard HEAD Uncommits all uncommitted operations Add git reset –hard HEAD^ go back to the previous version git reset –hard HEAD^ go back to the previous version git reset –hard HEAD~100 go back to the previous version git reset – hard < commit > back to the designated version of git checkout the route/route. The PHP back to the latest version of git checkout d98a0f565804ba639ba46d6e4295d4f787ff2949 Git checkout —

Discard workspace changes. If the file has been added to the staging area, it will be restored to the staging area. Otherwise, it will be restored to the repository state. Git checkout —

Git checkout —

Git reset HEAD

= git reset HEAD

= git reset HEAD

= git reset HEAD

If you want to undo an inappropriate change that has been committed to the repository, refer to version Rollback, but only if it has not been pushed to the remote repository






  • Delete/rename

Git rm –cached

git mv


Remote warehouse

  • Creating an SSH Key

Ssh-keygen -t rsa -c “[email protected]” Pub is the Key pair of the SSH Key. Id_rsa is the private Key and cannot be leaked, id_rsa.pub is the public Key, you can safely tell anyone, copy the content and add it to Github

  • Remote warehouse

Git remote add origin [email protected]: michaelliao/learngit git associated remote warehouse, the name of the remote repository is the origin, this is the default git term, can change to other, Git push -u origin master git push -u origin master git push -u origin master It also associates the local master branch with the remote Master branch, In the later push or pull can simplify the command git push origin master the local branch of the master the latest modification of the push to making git clone [email protected]: michaelliao/gitskills git Git automatically matches the local master branch with the remote master branch. Git remote git remote git remote git remote Git pull git pull -b

origin/

Create a remote Origin branch to the local Git branch –set-upstream

origin/

specifies the connection between the local dev branch and the remote dev branch



Branch management

  • Create a branch

Git checkout -b

Git branch

git branch

Merge branches to the current branch, Git branch -d

Delete a branch git branch -d

Forcibly deleting branches (unmerged branches)




  • BUG branch

Git Stash stash is the repository of the current work site, Restore the stash list check the stash git Stash apply restore the stash stash drop delete the stash stash pop restore and remove the stash git stash Apply stash@{0} multiple times to restore the specified stash

Label management

  • Create a label

Git tag git tag git tag git tag git tag git tag git tag git tag git tag git tag “Instructions”

Create a label with instructions

  • Operating the label

Git tag -d

Delete the tag git push origin

push a tag to a remote repository git push origin :refs/tags/

Delete remote tags (delete local tags before deleting remote tags)


export

Git archive -o /d/ WWW /update.zip HEAD $(git diff HEAD HEAD^ –name-only) git archive -o Git config core-quotePath false If the exported file is displayed as Unicode, configure this option

Other configuration

Git config core.gitproxy=socks5://127.0.0.1:1080 Git config core.filemode false Ignore file permissions