Common Git Commands

Source: Internet
Author: User
Tags tagname using git git commands

    1. Initialize Warehouse: Create mkdir <name> switch directory cd <name> initialize git init
    2. Set User: git config user.name "someone"
    3. Set up mail: git config user.email "[email protected]"
    4. New file: Git add <file> put files into staging area
    5. Commit file: Git commit-m "shuoming" to put the file in the branch
    6. View file modification status: Git status
    7. See what's Changed: Git diff
    8. View commit log: Git log parameter--pretty=oneline only show one line above
    9. Version fallback: head^ represents the previous version, head~100 represents a forward 100 version, fallback to the previous version: Git reset--hard head^, fallback to the specified version of git reset--hard xxxxx (several version numbers), The hard parameter indicates a rollback to the last commit, without rolling back to the uncommitted state.
    10. View history command: Git Reflog, can view version history
    11. . Git is a repository, stage is staging area, master is the first branch, add is put into staging area, commit commits to branch, each modification does not commit to branch if not add to staging area
    12. Git checkout--<file> can discard changes to the workspace and let the file go back to the last add or commit function, with no add
    13. Git rest HEAD <file> can undo the staging area changes, put them back in the workspace, use the Add but no commit, and use version fallback if commit
    14. RM Deletes the workspace physical file, git rm deletes the file from the repository, then git commits it, and if it has been submitted to the repository, you can use git checkout-<file> restore to recover the deleted file.
    15. Use $ ssh-keygen-t rsa-c "[email protected]" to create the RSA key pair, and then the C-drive user to find the. SSH folder and then add the pub key in GitHub background. Only people who have added a public key can push
    16. Remote Basic operation
        1. To view a remote library that currently exists: Git remote
        2. Associated remote connections: git remotes add <name> <ssh|htts>
        3. First time push Master:git push-u Origin Master
        4. Version push to server: git push <name> Master
        5. Update online version: Git pull <name> Master
        6. Clone an existing version: Git clone <ssh|htts>
    17. Branch Management
        1. View branches: Git branch
        2. Create a branch: Git branch <name>
        3. Switch branches: git checkout <name>
        4. Create + toggle: Git checkout-b <name>
        5. Merge a branch to the current branch: git merge <name> (equivalent to branch updates and commits)
        6. Delete branch: Git branch-d <name>
        7. Delete GitHub branch: git push orgin:refs/heads/<name>
    18. Resolve conflicts, require manual resolution of conflicts when prompted for conflicts, and then view the branching merge diagram: git log--graph
    19. Combined with the --no-ff(禁用Fast forward) parameters can be combined with the normal mode, the merged history has branches, can see that has been done
        1. git log--graph--pretty=oneline--abbrev-commit
        2. Git merge--no-ff-m "merge with No-ff" Dev
    20. Modify the bug, the current branch has been modified but not submitted, but also switch to another branch
        1. Using the git stash command to store the work site
        2. Use Git stash list to view stored live
        3. Use git stash apply to restore the scene (multiple restores) and then use Git stash drop to delete the scene
        4. Use git stash pop to recover and delete stash content as well
    21. If you want to discard a branch that has not been merged, you can use git branch-d <name> forcibly delete it.
    22. Multi-person collaboration
        1. First install the key, then clone the repository, then use B to drop the new branch
        2. View version of Git remote-v. Create local and remote branches corresponding to the branch using git checkout-b branch-name origin/branch-nam
        3. Push branch: Git push Origin Branch-name
        4. If the push fails, use GIT pull to drop the latest file, resolve the conflict, and then try the push again.
        5. If you are prompted "No tracking information"
          1. You need to create an association: GIT branch--set-upstream branch-name origin/branch-name
    23. Label
        1. Add tag: Git tab-a <tagname>-m < description >
        2. View all tags: git tag
        3. View tag details: Git show <tagname>
        4. Delete tags git tag-d <tagname>, remove remote tags: git push origin:refs/tags/<tagname>
        5. Push to remote: Git push origin <tagname> or Git push origin--tags to push all tags
        6. Rollback by label: git checkout Tag
    24. You can fork the open source warehouse on GitHub and have the read and write permission of the fork to pull the request to the official
    25. . gitignore fill in the file name to ignore
    26. ? using Ubuntu or Debian to build a git server

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.