1. Obtain the GIT repository of the project
The first is to create a git repository in an existing directory by importing all the files.
To start using git to manage an existing project, run $ git init in the directory where the project is located.
After initialization, a directory named. Git will appear under the current directory. All the data and resources required by git are stored in this directory. The second is to clone a new image repository from an existing git repository. If you want to contribute to an open-source project, you can first copy the GIT repository of the project.
git cloneCommand. Git collects all the data of the Project history (each file version ).
2. Record every update to the warehouseNext, make some modifications to these files. After completing the objectives of a stage, submit this update
Warehouse. For any file, there are only three States in git: committed, modified, and staged ). When git manages a project, the file is transferred to three working areas: git's
Working directory,
Temporary Storage Area, And
Local Repository.
Working directoryAll the following files are in either of these statuses: tracked or not tracked.
- Tracked files are files that have been incorporated into version control management. They are recorded in the previous snapshot. After a period of time, their statuses may not be updated, modified or placed in the temporary storage area.
- Other files are not tracked. They neither have snapshots of the last update nor are in the current temporary storage area. When cloning a repository for the first time, all files in the working directory belong to the tracked file and the status is not modified.
After editing some files, git marks these files as modified. We gradually put these modified files
Temporary Storage AreaUntil all these temporary files are submitted at the last time. Appendix:
3. operations that can be performed on files
- Check the status of the current file. You can use
git statusCommand
- Trace new files and use commands
Git add starts to track a file
Save modified files,Save the modification and rungit addCommand (this is a multi-function command: you can start to track new files, or put tracked files in the temporary storage area. It can also be used to mark conflicting files as resolved during merge)
- Ignore some files. Some files do not need to be managed by git, and they do not need to always appear in the list of untracked files. You can create
.gitignoreTo list the file modes to ignore.
- View saved and unsaved updates,
git statusThe display is relatively simple. It only lists the modified files. To view the modified files, you can usegit diffCommand. Simplegit diffBut it shows that there are no temporary changes, rather than the difference between this job and the last commit.
- Submit the update and command
git commitBefore you can submit a temporary file, make sure that you have not modified or created any new file.git addOtherwise, the changes that have not been saved will not be recorded during submission. Therefore, usegit statusCheck whether all of them have been saved, and then run the submit command.git commit。
- Skip Using the temporary storage area. Although you can carefully prepare the details to be submitted by using the temporary storage area, it is sometimes cumbersome. Git provides a way to skip the use of temporary regions.
git commitAdd-aOption, git will automatically save all the files that have been tracked and submit them together, thus skippinggit addStep.
- To remove a file from git, you must remove it from the list of Tracked files (specifically, from the temporary storage area) and submit the file. Available
git rmCommand to complete this task, and then delete the specified file from the working directory, so that it will not appear in the list of untracked files.
- Unlike other VCs systems, git does not track file movement operations.
mvCommand. To rename a file in git, you can do this:$ git mv file_from file_to
In fact, rungit mvIt is equivalent to running the following three commands:
$ mv README.txt README #move$ git rm README.txt #remove$ Git add readme # Trace new files
In this separate operation, git will realize that this is a renaming.
4. view submission history
- After submitting several updates or cloning a project, you can use
git logCommand to view.
- By default, no parameters are required,
git logAll updates are listed Based on the submission time, and the most recent updates are listed at the top.git logThere are many options to help you search for submissions you are interested in. Next we will introduce some of the most commonly used. Git log-pOption.-2Only the last two updates are displayed.
git logMany abstract options are available, such--stat, Only show the summary of the number of rows to be added and modified, and so on.
- In addition to the custom output format options,
git logThere are also many practical options to limit the output length.
- The gitk released with git is such a tool, basically equivalent
git logVisual version of the command.