Git workflow summary

What is git

Git is a tool for tracking incremental changes to your files, making it easy to find and even roll back changes to your files in the future

Inbox

Git documentation

  • Git documentation
  • Novice tutorial

Basic concept

Git git git git git Git git

state

  • ▪ Modified
    • If we add a file, it becomes a traced file, and if we modify it, we don’t add it and it becomes modified
  • ▪ Passage Ten
    • The fileaddpass
  • ▪ Committed
    • commitpass
  • There’s a special state
    • Untracked
    • why
      • There are some files that we keep in git folders but don’t want to share so we don’t have to track them (or join them).gitignoreFile)
  • The command
    • git status

area

  • • Working Directory
    • Where you write code
    • All the files are here, untracked, tracked, etc
  • • Staging area
    • Working directory changes after:Git add file name, put the corresponding file into the staging area
    • Where we store code for phased changes. The type of file we want to save is the version, or version number, of the file
    • Git doesn’t keep track of all our additions and subtractions of every word, it keeps track of all our phased changes to our code (completing a small feature)
  • • Git repository
    • Final state
    • If we finish a feature and want to make it into a version, we add it to the Git repository
    • The git commit -m function is complete

Note that the remote repository is actually an extension, or a backup, of our local repository. Once the local repository is used, the remote repository can be operated on again

Workflow basic commands

git init

  • To generate a.gitdirectory
    • All information about our project and Git will be stored in the corresponding. Git directory

git add .

Add all files in the current directory from work dir to stage

git commit

  • Each commit generates a version hash value
  • Incremental submission
    • Add commit for each update
  • Repair commit
    • I need to fix a bug urgently, but I don’t want to create a big new version, so I use this
    • Git commit -- amend-m
      • Note that this comment will modify the comment you submitted last time, preferably the same as the branch you submitted to in an emergency

git status

Workflow Description

To start tracking a project, initialize the project with git init

After editing some files and making sure that the function is complete, I will add the file to the Stage with git add file name. Then I will continue to develop. After finishing a little bit, I can add the file to the Stage.

When some files do not need to be committed to the repository, we use the git reset file name to remove them from the staging area.

Or, if we add a file to the Stage, we edit it again and it changes to the Modified state, but we find that the subsequent edit is not what we want, and we need to revert to the Stage state using git Checkout

Note the difference between “reset” and “checkout” : “reset” changes the area of the file and does not affect the file itself. Checkout changes the file itself, not the area of the file.

Rm –cached file name: we added a cached file to the Repository, but we later found that the file should not be committed, so we need to delete it from the Repository, but we should not delete it from the work dir. Caution Commit this operation. Otherwise, the operation will not be displayed on the page

Other Basic Operations

Cancel the reset

  • Undo from staging to workspace

    • For example, I made payment and “like” functions at the same time, but I just want to commit the payment function as one version this time, but I accidentally added the files related to “like”, so I need to use reset
    • // Undoes a specified file from the staging area Git reset HEAD Specifies the name of the file
  • I want all the staging areas withdrawn

    • The Add part is out of order
    • git reset HEAD .
  • Restores a file to the staging area

    • Git Checkout
  • delete

    • Do not track a file

      • Git rm --cached file after rm, you need to commit this operation, otherwise rm will remain in the staging area git commit -m fixCopy the code
    • Directly and completely delete the corresponding files locally and in the workspace

      • Git rm name
      • Finally, if you want to reflect to the warehouse, it must be carried outcommitoperation

See the log

  • git log: Displays detailed information about each COMMIT
  • git log --oneline: Concise view
  • git reflog

branch

User system, content publishing system, a system includes many functions on the release, we need to add a payment function on the original basis, this time to open a new line to continue to execute, if possible, just start directly

rebase

Just a big version update for me (payment). There will be a lot of small steps: for example: get price, wechat pay, Alipay pay, payment password, payment verification and so on. We end up with a commit, merge, and merge on the main branch, but we don’t want to see these bits and pieces on the main branch, so we use a rebase to merge them. Combine these dozens of submissions into one: Payments.

Horizontal and vertical analysis

  • Horizontal is to find the corresponding son, if you want to find multiple times, you have to use multiple^Not just one^ Numbers greater than 1.^nIf n is greater than 1, it goes left to right

merge

  • The basic grammar

    • Git branch --merged Git branch --no-merged Git branch --merged git branch --no-merged git branchCopy the code
  • Conflict with

    • what
      • Multiple branches commit to the same file, and then merge the branches into a conflict
    • how
      • Viewing conflicting Files
      • Modifying conflicting Content
      • Rework, add and submit

The label

Usually we label certain things, some fixed, stable version code

Developed on stable versions:

  • Create multiple branches to develop
  • Like a branch to fix a bug
  • A branch to test new features

How good

  • Branches are usually used for development, and adding a label to the corresponding COMMIT indicates that the corresponding version is stable and ready for release
    • Generally used in publishing

Command summary

More specific commands can be found in the documentation or in the rookie tutorial (in the initial Inbox)

init

status

add

commit

log

reflog

rm

reset

diff

branch

checkout

merge

rebase