"Git" (1)---workspace, staging area, repository, remote repository

Source: Internet
Author: User
Tags using git

Workspaces, staging area, repository, remote repositories

first, the concept1, four working areas

Git has four workspaces locally: working directory (working directory), staging area (Stage/index), repository (repository or Git Directory), and git repository (Remote directory). The conversion relationship between the files in these four regions is as follows:

Workspace: The workspace is where you normally store your project code

index/stage: Staging area for temporary storage of your changes, in fact it's just a file that saves the information that will be submitted to the file list

Repository: The warehouse area (or repository) is where the data is stored securely, which contains data that you submit to all versions. Where head points to the latest version to be placed in the warehouse

remote Repository, managed code server, can simply be considered as a computer in your project group for remote data exchange

2. Work Flow

The workflow of Git is usually this:

1, in the working directory to add, modify the file;

2, the need for version management files into the staging area;

3. Submit the file of the staging area to the Git repository.

As a result, Git manages files in three states: modified (modified), staged (staged), committed (committed)

3. Four states of the file

Version control is the version of the file control, to modify the file, submit, and so on, first of all to know what the state of the file, or it may be submitted now do not want to submit the file, or to submit the file is not submitted.

Git does not care about the specific differences between the two versions of a file, but rather the overall change of the file, and if the file is changed, a snapshot of the new version of the file is generated when the commit is added, and the method of judging whether the file is changed is

The SHA-1 algorithm calculates the checksum of the file.

untracked: not tracked, this file is in a folder, but is not added to the GIT library and does not participate in version control. The git add state changes to staged.

unmodify: The file is already in storage, unmodified, that is, the file snapshot content in the repository is exactly the same as the folder. There are two places for this type of file, and if it is modified, it becomes modified.

If you use Git rm to move out of the repository, you become a untracked file

Modified: The file has been modified, only modified, and nothing else has been done. This file also has two places, through git add to enter the staging staged state, using git checkout is discarded modified,

Returning to the unmodify state, this git checkout removes the file from the vault, overwriting the current modification

staged: staging State. Executing a git commit synchronizes the changes to the library, where the files in the library become consistent with the local files and the files are in the Unmodify state. Executes git reset HEAD filename cancels the staging,

File status is modified

The following figure illustrates the transformation of these four states in a good way:

New File--->untracked

Use the Add command to add the newly created file to the staging area--->staged

Use the commit command to submit a file for the staging area to the local warehouse--->unmodified

If you modify a file for the unmodified status---> Modified

If you do a remove operation on a file with a unmodified status--->untracked

二、四个 Area Common commands1. Create a new code base
# Create a new git code base in the current directory git init # Create a new directory and initialize it to a git code base git init [project-name] # download a project and its entire code history git clone [url]
2. View file Status
# View the specified file status git status [filename] # View all file statuses git status
3. Work Area <--> Staging Area
#add specified file to staging areagit add [file1] [file2] ...#Add the specified directory to staging area, including subdirectoriesgit add [dir]#Add all files from the current directory to staging areagit Add.#when we need to delete the file on the staging area or branch, and the workspace does not need the file, you can use (?? )git rm file_path#when we need to delete the file on the staging area or branch, but it needs to be used locally, this time the file will not be directly push, if the push is re-add then there will be. git rm--cached file_path#directly add the file name from staging area to the workspace, and if the workspace already has the file, select Overwrite#adding "branch name" + file name means pulling the file from the branch name and overwriting the file in the workspacegit checkout
4. Workspace <--> Resource Library (repository)
# the staging area--Repository (repository) git commit-m ' This commit description ' # If it appears that the unnecessary file commit or the last commit is wrong or does  not want to change the staging area content, just want to adjust the submitted information # Remove unnecessary files added to staging area git Reset HEAD filename # removes the last commit (which will change directly to the Add state   )git reset head^#   git reset--soft  head^
5. Remote Operation
# retrieve changes to the remote repository and merge with the local branch git Pull # upload locally designated branch to remote repository git push
6. Other common commands
# Displays the current git configuration git config--list # edit a git configuration file git config-e [--global] # before the initial commit, you need to configure the user's mailbox and user name, using the following command: git config--global user.email "[email protected]" git config--global user.name "Your name" # bring up Git's help document git--help # View Help documentation for a specific command git + command--help # view git's version git--version

I just occasionally calm down and ponder over all the past. It's not worth condemning those old times that have been naïve and dull. After all, the days ahead are still long. Keep encouraging yourself,

The day is bright, is a new beginning, but also the unknown journey (Colonel 18)

"Git" (1)---workspace, staging area, repository, remote repository

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.