Git initialization

1. Query the current git version:

git --version

2. Create a new working directory, such as: in the root directory of the git user, create a demo project

cd /home/git/
mkdir demo cd demo git init //Create a working directory and add a .git file to the working directory
result: Initialized empty Git repository in /home/git/.git/

3. Add a new file under the project and submit touch test.txt //Create a test.txt file

echo "Hello" > test.txt //Add content 
to test.txt git add test.txt //Add the test.txt file to the buffer
git commit -m "Add test.txt file" //Submit the file to The submission description of the local warehouse -m parameter setting is: "Add test.txt file"
result:
 [master (root-commit) 75c950c] New test.txt file //This submission is on the branch of master, and it is this branch The first submission (root-commit), the submission ID is 75c950c
  1 file changed, 1 insertion(+) //This submission modifies a file, including a line of insertion
  create mode 100644 test.txt //This submission creates new file test.txt

4. Workspace contains critical file search

git grep "test"
result:
test.txt:test

  Thinking: git puts the repository (.git directory) in the root directory of the workspace, so must Git-related operations be performed in the root directory of the workspace? In other words, when the workspace contains subdirectories, and the Git command is executed in the subdirectory, how to locate the repository?

   In fact, when an operation is performed in a subdirectory of the Git workspace, the .git directory will be recursively queried in the workspace directory in turn. The found .git directory is the repository corresponding to the workspace, and the directory where .git is located. It is the root directory of the workspace , and the file .git/index records the status of the workspace file (actually the status of the staging area)

Show the location of the repository .git directory:

git rev-parse--git-dir
result:
/home/git/demo/.git

Show the workspace root directory:

git rev-parse --git-dir
result: /home/git/demo

Display a directory relative to the workspace root:

git rev-parse --git-dir
result:a/b/c

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324900226&siteId=291194637