Common git commands

Source: Internet
Author: User
Tags tagname git commands

A global configuration

    • git config--gobal core.autocrlf false
    • git config--global user.name "Carlos"
    • git config--global user.email "[Email protected]"
    • GIT init//Initialize a repository

Two common operations

  • git Add//Add to buffer can participate in-a
  • git status//view current status
  • Git commit-m "XXX"//Submit Code
  • git diff//view different
  • git log//view Log
  • git log--pretty=oneline
  • git reset--hard head^
  • git RM file name (including path) removes the specified file//delete file from Git
  • Git reflog records every single command you have.
  • Git checkout--file can discard modifications to the workspace
  • Git checkout--in the file command--very important, not--becomes the "switch to another branch" command
  • Git reset HEAD file can undo staging area's changes
  • git remote add origin [email protected]:p Ath/repo-name.git to associate a remote library;
  • Git push-u origin master uses the command to push all the contents of the master branch for the first time
  • git clone clones a local library:
  • git clone [email protected]:michaelliao/gitskills.git
  • git checkout-b dev # create dev branch, then switch to Dev Branch
  • The git branch command lists all branches, with an * number in front of the current branch
  • git merge Dev merges the work of the Dev branch into the master branch
  • git branch-d Dev removed the dev branch
  • Git merge--no-ff-m "merge with No-ff" Dev merges the branch code--NO-FF parameter, which means that fast forward is disabled so that branch information can be seen from the branch history.
  • Git stash git also provides a stash feature that can "store" the current work site, and then continue to work after resuming the site later
  • Git stash apply recovery, but after recovery, stash content is not deleted
  • git stash drop to delete
  • git stash pop, restore the stash content also deleted
  • git branch-d feature-vulcan forcibly removed
    • Git put stash content somewhere, but it needs to be restored, there are two ways
    • One is to use git stash apply recovery, but after recovery, stash content is not deleted, you need to use git stash drop to delete;
    • Another way is to use git stash pop, restore the stash content also deleted

Three tags

    • git tag <name> can hit a new tag
    • git tag View all tags
    • git tag v0.9 6224937 #v0.9 Tag name 6224937 commit ID
    • Git show <tagname> view tag information
    • git tag-d <tagname> Delete tags
    • Git push origin <tagname> can push a local tag;
    • Git push origin--tags can push all the local tags that have not been pushed;
    • Git tag-d <tagname> can delete a local tag;
    • git push origin:refs/tags/<tagname> can delete a remote tag.

Four branches

    • GIT encourages the use of branching:
    • View branches: Git branch
    • Create a branch: Git branch <name>
    • Switch branches: git checkout <name>
    • Create + switch branches: git checkout-b <name>
    • Merge a branch to the current branch: git merge <name>
    • Delete branch: Git branch-d <name>
    • View Branches
    1. Git branch
    2. Git branch-v
    • Create a branch git branch A1.0
    • Switch branch git checkout A1.0
    • Delete Branch
    1. git branch-d A1.0//If the branch does not merge into the main branch it will error
    2. git branch-d A1.0//Forced Delete
    • Merge A into B
    1. git checkout B
    2. git merge A
    • Branch Merge
    1. For example, if you want to merge the branches in development (develop) into a stable branch (master),
    2. First switch the Master branch: Git checkout master.
    3. Then perform the merge operation: git merge develop.
    4. If there is a conflict, you will be prompted to call Git status to view the conflicting file.
    5. Resolve the conflict, and then call git Add or git rm to save the resolved file.
    6. After all conflicts are resolved, Git commit commits the changes.

Five ignore files. Gitignore

Create a special. gitignore file in the root directory of the Git workspace, and then fill in the file name you want to ignore, and git will automatically ignore the files
The principle of ignoring files is:

    • Ignoring the auto-generated files of the operating system, such as thumbnail images;
    • Ignoring compile-generated intermediate files, executables, and so on, that is, if a file is automatically generated from another file, the automatically generated file does not need to be put into the repository, such as Java compilation generated by the. class file;
    • Ignore your own configuration file with sensitive information, such as the configuration file that holds the password.
    • There is no need to write from scratch. gitignore file, GitHub has prepared a variety of configuration files for us, just a combination to use. All profiles can be viewed directly online: Https://github.com/github/gitignore

Six GitHub

    • Ways to pull items from GitHub git clone https://XXXXXXXXX.git


Seven person configuration

The previous user's git configuration file is placed in a hidden file in the user's home directory. Gitconfig

=1447675994falsetrue== =  == log-1"log--color--graph--pretty=format: '%cred%h% Creset-%c (yellow)%d%creset%s%cgreen (%CR)%c (bold blue) <%an>%creset '--abbrev-commit '

Eight. Gitignore format
Files to ignore in this warehouse

    • Ignores all. A end-of-file *.a
    • But LIB.A except!LIB.A
    • Just ignore the TODO file under the project root directory, not including Subdir/todo/todo
    • Ignore all files under the build/directory build/
    • Ignores Doc/notes.txt but does not include Doc/server/arch.txt Doc/*.txt
. Project.pydevproject.settings/*.NCB*. suo*. User.cproject*.O

Common git commands

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.