Git local base operations

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

1.Git Introduction (Installation and configuration) Installation of 1.Git (http://www.git-scm.com/download/) 2. git configures "git config" to query for git commands:
    • git install root directory/doc/index.html can be queried, the more convenient way is to use Git to make targeted calls through Help. (in the query Config Help document, for example, the syntax is:git config--help/git. config)
    • Pro Git reference documentation
    • The configured information for git will be stored in the user directory (example C:\Users\Administrator) . Gitconfig in the file
Three levels of GIT configuration: System (for systems) global (for current users) local (for the current operation of the warehouse)
3.git User name additions and deletions
    • git add User:git config--global--add user.name username
    • git delete User:git config--global--unset user.name username
    • Git lookup User:git config--global--list
4.git Command Alias
    • git config--global alias.co "checkout"

2.Git Workflow Basic Operations 0.git file type (file Object ID:40 hexadecimal characters)
    • blob (Binary large object): text file, binary file, link file
    • Tree: Directory
    • Commit: Historical submissions
    • tag: Point to a fixed history submission
1.git Creating a Warehouse
    • Bare_repository: There is no difference between the workspace and the working directory. (git init--bare repositoryname)
    • Non_bare_repository: There is a separate. Git directory under the repository directory. (git init repositoryname)
    • Create a non_bare_repository repository under the repository directory you created (git init), or you can use it to incorporate existing projects into Git management .
    • Clone another repository (git clone sourcerepo destinationrepo)
2.git the file structure of the managed project
    • Working directory (workspace)
    • Staging Area (Staging): Represents the status that needs to be submitted.
    • History Repository (historical warehouse).
3.git Management of project files
    • gitadd: Adds a file from the workspace to the staging area.
    • git commit: Submit a file in staging area as a history
    • git status: See the difference between the workspace and staging area ( Red ), the difference between staging area and the last commit history ( green )
    • git rm: Cleans up files in staging area and workspaces. (only clear files in staging area:git rm--cached FileName)
    • git mv: Modify files in the workspace (rename, move)
    • git checkout: Check out deleted files to workspace from staging area;
    • Gitignore: Indicates that the specified file in the workspace is not added to the staging area or history record,
For cases where files are added to staging area and multiple files need to be ignored, the method is taken inunder working directoryCreate a named. Gitignorefile in which the declaration ignores the file format as follows:
      • *~: Pass the temporary file.
      • *. [OA]: A file with a suffix named O or a.
      • *.txt: A file with a suffix named txt.
      • folder/: A folder with a wildcard name.
      • **/res: A file named res under each folder.
      • !test: Indicates that a file named test is not ignored.
      • \!test1: for ignoring filenames! The beginning of the file, you need to add a backslash "\" to escape.
4.git of Staging Area
    • Git's content for staging area is maintained in the . Git/index file.
Local branch and merge of 5.git
  • git branch: Create a branch. (Typically, a branch name, such as Master Branch Master, will typically point to the most recent commit of that branch)
  • git tag: Tag a specific hit, and query the tag you created. (There are two types of tag: 1. Lightweight Local:git tag "TagName" Commitno , 2. With annotations to be pushed to the server: git tag-a "TagName" Commitno.
  • git checkout: Switch between branches. (creating branches and switching branches can be fused as a single command:git checkout-b branchname). If checkout to a tag, then the HEAD is in the state of detached, that is, if you do not create a branch of this tag and checkout to the new branch, then you make any changes and submissions will not be saved.
  • git stash: Saves local modifications < stealth Commit&gt before switching branches, but does not generate a new commit. Save git stash save-a "stashmessage" 。 To view the modified records stored in this branch:git stash list。 To restore a saved record: git stash pop--index [email protected]{No.} 。 When the record is recovered, the records saved by stash will not exist. If you want to save Stash records, you can use:git stash apply--index [email protected]{No.}. To clear records in stash: git stash drop [email protected]{No.} 。 Clear all Stash:git stash Clear。 )
  • git merge: merge branches. There are two kinds: one is fast-forward: Two records is a parent-child relationship; Non-fast-forward: Two records have a common parent node, and you need to deal with the conflict before committing the merge. (in the branch to be merged, some files are conflicting and you want to discard the merge:git merge--abort.) )
  • git log: View git's history submission (git log--oneline--decorate--graph--all)
6. View and compare historical records
    • git show: Show submission Information
    • gitlog: Show log
    • git diff: Compare differences (compare the difference between the current workspace and the last commit version)
7. Undo Changes
    • git checkout: Restore the workspace (Use records from staging area to restore the workspace, such as Git status has a modified record, this command can be undone)
    • git reset: Restore the Staging area (using a single submission result to restore the staging area)
    • gitclean: Remove files that are not committed and not added to staging area in the working directory (git clean-n shows the files that will be deleted,git clean-f delete files,git clean-df Delete files and directories. For files that need to be purged in the. gitignore file in the GIT working directory,git clean-n-x to view the ignored files in the. Gitignore that will be deleted.
    • git revert: Generate new commits and overwrite previously committed changes

8. Rewrite history
    • git commit--amend: Overrides the current point of history submission
      • Point to several versions before a commit: ([version pointer]~: The previous version of the version pointed to by the version pointer. [Version pointer]^n: the first n versions of the version pointed to by the version pointer]
    • git rebase: maintains a linear history similar to git merge.
    • git reset: (git reset--hard [history commit]: Restores the staging area and workspace to the established history commits and moves the head pointer. git reset--mixed: Restore staging Area, and move the head pointer,--mixed as the default command. git reset--soft [history commit]: Move only the head pointer. )
    • git reflog: Lists the history that the head points to.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Git local base operations

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.