Disclaimer: Some content refers to the blog post of the master for the convenience of personal reference;
The project development git version control directory is roughly as follows:
- Directory: The folder you want to set as the git working directory. In this directory, git init initializes the local library and generates a hidden .git folder. Place code files in this directory, which is the workspace;
- WorkSpace: Place the project code or related files that need to be uploaded to git. These directories and files form the workspace;
- .git: Directory that stores git management details (including the version library (including the staging area and local library) and other files as shown in the picture) , which is automatically created during git init initialization (don't touch these files if nothing happens)
- index/Stage: Staging area. If the files in the workspace are added to the staging area using git add <path> or git add ., they will be saved here;
- Local Repo: local warehouse, a version library stored locally; HEAD is the current development branch;
- Stash: is a work status saving stack, used to save/restore the temporary status of WorkSpace;
======================
1. .git folder
For details, please refer to the blog post: Detailed explanation of .git folder. Detailed explanation of .git folder - Programmer's Basecamp
- The folder used to manage the git warehouse has a lot of content, including the staging area and local libraries, which are all in the folder;
- Creation method: Create with git init command; existing version of the project can be pulled down remotely;
- A brief introduction to the content
hooks:(钩):存放shell一些脚本
info:存放仓库信息
objects:存放所有的git对象
refs:heads:保存当前最新一次提交哈希值
2. Local warehouse (repository)
- The local warehouse is under the hidden folder .git
- The file is submitted to the local library through git commit in the staging area.
- Local library files are submitted to the remote warehouse through git push
git commit -m “注释内容” <文件名> //提交暂存区内容到本地仓库 git reset --hard\soft <要回退的版本号> //回退已提交本地库的版本
3. Version library
The storage location of the version library is in the .git folder, and the staging area and local library are stored under the version library;
4. Work area:
At the same level as the .git folder, store code or other files that need to be controlled by git. This space is the workspace;
5. Temporary storage area
- Function: What is atomicity, what convenience and multi-function are submitted separately, we will not study it for the time being;
- Order:
添加到暂存区命令:
git add <path> //添加指定path,这里的path可以是文件,也可以是文件夹
git add . //添加所有文件
git add -u //添加新创建的文件,只添加已修改和删除的文件
--------
//如果要撤销提交文件到暂存区,
git rm --cached <path> //撤销暂存指定文件或文件夹
6. Remote warehouse
- Remote warehouse category
For example, if you create your own project on github or gitee website, you can push the code to the remote warehouse.
- How to create a remote warehouse
- Push to remote repository
7. Branch
When multiple people are developing, in order to prevent mutual interference, or to be responsible for different modules of a project, set up different branches to improve the efficiency of collaborative development;
- Commonly used commands:
git branch -v //查看分支
git branch <分支名> //创建分支
git checkout <分支名> //切换分支
git merge <分支名> //把指定的分支合并到当前分支上
-------
git branch (-m/-M) <旧分支名> <新分支名> //重命名分支(新分支名要是重复,用M强制重命名)
git branch (-d/-D) <分支名> //删除分支