Git local basic operations
1. Git introduction (installation and configuration)
1. Git installation (http://www.git-scm.com/download/) 2. Git configuration [git config] About git command query method:
- The/doc/index.html file in the root directory of git can be queried. A more convenient way is to use help for targeted calls when using git. (The syntax for querying the config help document is git config -- help/git help config)
- Pro git Reference Document
- The configuration information of git is stored in the. gitconfig file in the user directory (for example, C: \ Users \ Administrator ).
Three levels of git configuration: system (for the system) global (for the current user) local (for the current repository) 3. add, delete, modify, and query git usernames
- Add git users: git config -- global -- add user. nameUsername
- Git: git config -- global -- unset user. nameUsername
- Git: git config -- global -- list
4. Alias for git commands
- Git config -- global alias. co "checkout"
2. Basic Git workflow operations 0. git file type (file object identifier: 40 hexadecimal characters)
- Blob (binary large object): Text File, binary file, link file
- Tree: Directory
- Commit: Submit history
- Tag: point to a fixed Historical submission
1. Create a repository using git
- Bare_repository: there is no difference between a workspace and a working directory. (Git init -- bareRepositoryName)
- Non_bare_repository: there is a separate. git directory under the repository directory. (Git initRepositoryName)
- Create a non_bare_repository repository under the created repository directory (git init). It can also be used to manage existing projects in git.
- Clone Other repositories (git cloneSourceRepo DestinationRepo)
2. File structure of the project managed by git
- Working directory (workspace)
- Staging area: indicates the status to be submitted.
- History repository (historical repository ).
3. git manages project files
- Git add: add files from the workspace to the temporary storage area.
- Git commit: Submit files in the temporary storage area as historical records
- Git status: view the difference between the workspace and the temporary storage area (red), the difference between the temporary storage area and the last submitted historical records (green)
- Git rm: clears files in the temporary storage and workspace. (Only clear files in the temporary storage zone: git rm -- cachedFileName)
- Git mv: modify files in the workspace (rename, move)
- Git checkout: detects deleted files from the temporary storage area to the workspace;
- Gitignore: indicates that the specified file in the workspace is not added to the temporary storage area or history,
To add files to the temporary storage area and ignore multiple files, you can create a file named. gitignore in the working directory. The format of the file to be ignored is declared as follows:
-
- *~ : Wildcard temporary files.
- *. [Oa]: a wildcard file with the suffix o or.
- *. Txt: a file with the suffix txt.
- Folder/: a folder named folder.
- **/Res: configure the files named res in each folder.
- ! Test: indicates that the file named test is not ignored.
- \! Test1: for ignoring file names! Escape the file with a backslash.
4. git staging zone
- Git maintains the content in the staging area in the. git/index file.
5. local branch and merge of git
- Git branch: Create a branch. (Generally, the branch name, such as the master node of the master node, points to the latest commit of the branch)
- Git tag: tag a specific commit; query the created tag. (Tag can be divided into two types: 1. Lightweight local: git tag"TagName"CommitNo., 2. git tag-a "that can be pushed to the server with annotations"TagName"CommitNo.)
- Git checkout: switch between branches. (A command can be used to create and switch branches: git checkout-B.BranchName). If checkout is a tag, the HEAD is in the detached state, that is, if you do not create a branch for this tag and checkout is a new branch, any modifications and commits you have made will not be saved.
- Git stash: Save the local modification <invisible commit> before switching the branch, but no new commit is generated. (Save: git stash save-"StashMessage". View the modification record stored in this branch: git stash list. Restore saved records: git stash pop -- index stash @{No.}. After a record is restored, the record saved by stash does not exist. To save the stash record, use: git stash apply -- index stash @ {No .}. Clear records in stash: git stash drop stash @{No.}. Clear all stash: git stash clear .)
- Git merge: merge branch. There are two types: fast-forward: parent-child relationship between two records; non-fast-forward: two records have a common parent node. You must first process the conflict and then submit and merge the records. (When some files in the branch to be merged conflict, you want to discard the merge: git merge -- abort .)
- Git log: view the historical commit status of git (git log -- oneline -- decorate -- graph -- all)
6. View and compare historical records
- Git show: displays the submission information.
- Git log: displays logs.
- Git diff: compare differences (compare the differences between the current workspace and the last submitted version)
7. Undo Modification
- Git checkout: Restore the workspace (use the record in the staging area to restore the workspace. If git status has a modified record, this command can be undone)
- Git reset: Restore the temporary storage area (use a submitted result to restore the temporary storage area)
- Git clean: Remove files not submitted in the working directory and not added to the temporary storage area (git clean-n displays the files to be deleted, git clean-f deletes the files, git clean-df deletes files and directories. For files that need to be cleared from the. gitignore file in the git working directory, git clean-n-X will view the ignored files in. gitignore that will be deleted)
- Git revert: generate a new commit and overwrite the previously submitted changes
8. Rewrite history
- Git commit -- amend: overwrite the historical commit currently pointed
-
- Pointing to several versions before a submission: ([version pointer] ~ : This version Pointer Points to the previous version of the version. [Version pointer] ^ n: The first n versions of the version pointed to by this version pointer)
- Git rebase: maintains a linear history, similar to git merge.
- Git reset :( git reset -- hard [historical commit]: restores the staging area and workspace to a specific historical commit, and moves the HEAD pointer. Git reset -- mixed: restores the temporary storage area and moves the HEAD pointer. -- mixed is the default command. Git reset -- soft [historical commit]: only move the HEAD pointer .)
- Git reflog: list the historical records pointed to by the HEAD.
Ubuntu perfectly installs and builds a Git Server
GitHub Tutorials:
GitHub tutorials
Git tag management details
Git branch management
Git remote repository details
Git local Repository (Repository) Details
Git server setup and Client installation
Git Overview
Share practical GitHub tutorials
How to Build and use Git servers in Ubuntu
Git details: click here
Git: click here
This article permanently updates the link address: