🎏 This is the 8th day of my participation in Gwen Challenge

0 x00 📢 preface

👇 Git getting started is linked below. Read the articles in that order at 👇.

1️ abandon to entry (1) 2️ discount on abandonment of Git (2)

This series of articles explains how to quickly master the functions and operation flow of each command through examples to get started with Git.

In this second installment, I introduce you to some very important and confusing basic concepts about Git.

0x01 Basic Concepts

The examples above show how to create a repository, temporarily store commit changes, view history, and more. The basic workflow is as follows:

  1. Modify files in the workspace.
  2. Optionally staging the changes you want to commit next time will only add the changed parts to the staging area.
  3. Commit the update, find the files in the staging area, and store the snapshot permanently to a Git directory.

If the Git directory holds a particular version of the file, it is committed. If the file has been modified and placed in the staging area, it is in the staging state. If changes have been made since the last check out but have not been placed in the staging area, the state is modified.

The conceptual terms mentioned above will be explained one by one.

Three states

Git has three states, and files can be in one of them: Committed, Modified, or staged.

  • Modified indicates that the file has been modified but not saved to the database.
  • Staging means that the current version of a modified file is marked for inclusion in the next committed snapshot.
  • Committed indicates that the data is securely stored in the local database.

The three stages

This gives Git projects three phases: Working Directory, Staging Area/Index, and.git Directory/Repository.

  • A workspace is a separate extract from a version of a project. These files are extracted from a compressed database in a Git repository and placed on disk for you to use or modify.
  • A staging area is a file that holds a list of files to commit next time, typically in a Git repository directory. Git’s term is “index”, but it is commonly referred to as “staging area”.
  • The Git repository directory is where Git holds your project’s metadata and object database. This is the most important part of Git, and this is where the data is copied when you clone repositories from other computers.

File status

Every file in the working directory is in one of two states: traced or not traced.

Traced files are files that have been versioned, were recorded in the last snapshot, and may be unmodified, modified, or put into staging after working for some time. In short, traced files are files that Git already knows about.

All files except traced files in the working directory are untraced files that neither exist in the records of the last snapshot nor are placed in the staging area.

0x02 Git phase Flow

  • Git add files to the staging area.
  • Git commit Generate and commit a snapshot for the staging area.
  • Git reset — files To undo the last git add files. You can also undo all temporary files with git reset.
  • Git checkout — files copies files from the staging area to the working directory to discard local changes.

Skip using the staging area

  • Git commit -a is equivalent to running git add to add all files in the current directory to the staging area and run it again.
  • Git Commit Files makes a commit containing the last commit plus a snapshot of the files in the working directory, and the files are added to the staging area.
  • Git checkout HEAD — files rollback to copy the last commit.

Some of the above git commands will be covered in more detail in a future article.

0x03 Diagram file state changes

Based on three states, three phases, document state and other conceptual relations drawn a flow chart 👇.

0 x04 📚 reference

Pro Git Online

0x05 Attention column

This article has been included in the column 👇, you can directly follow.

Read more | The series continues to be updated