This is the 7th day of my participation in the November Gwen Challenge. Check out the details: The last Gwen Challenge 2021

  • usegitIt’s been a long time, but it’s never been summed up, this timegitFor a summary and reflection.

Why use Git

  • Easy version control
  • Version control: Record all changes to items for easy reference and rollback.

Ii. Classification of version control

  • Local version control: Copy the entire project while manually recording the version, for example1.0.0.2.0.0Distinguish and manage.
  • Centralized versioning: A central server holds all version records from which others can retrieve or submit files.
  • Distributed version control: everyone owns all version records of the current project. Changes and other operations are performed locally, and you can push your changes to others.
  • Difference-based versioning: Keep a record of the differences between each file over time.

Git file status

  • Untraced: Files that are not logged by Git, such as files in.gitignore. The newly added files are often not tracked. They need to be added to the staging area, and then saved to the Git database for tracking. A state similar to and modified

  • Tracked: Files that are under version control. Only files that have been versioned have the following three states.

    • Modified: Modifies a file in the workspace. The Add operation has not been performed.

    • Passage Ten (passively ADDED): The modified document has been marked up and put into passage. Save without commit.

    • Commit (commited): A commit has been performed to commit a file from the staging area to the local database.

  • Git status Displays the current workspace status.

    • No changes in workspace:
       On branch main
       Your branch is up to date with 'origin/main'.
    
       nothing to commit, working tree clean
    Copy the code
    • There are changes in the workspace,.gitignoreThe file has been modified and needs to be processedaddEnter the staging area,commitCommit. orrestorePerform a recall operation.node_modules/The file under is not traced and needs to proceedaddandcommit
    On branch main
    Your branch is up to date with 'origin/main'.
    
    Changes not staged for commit:
      (use "git add <file>..." to update what will be committed)
      (use "git restore <file>..." to discard changes in working directory)
            modified:   .gitignore
    
    Untracked files:
      (use "git add <file>..." to include in what will be committed)
            node_modules/
    
    no changes added to commit (use "git add" and/or "git commit -a")
    Copy the code
  • Git status -s M has modified the file,?? Files that are not tracked by Git, files in A temporary storage area

 M .gitignore
?? node_modules/
Copy the code

4. View file modifications

  • git diff: View already inThe staging areaThe documents andNot temporaryWhat changes have been made to the file
diff --git a/.gitignore b/.gitignore index 960be9a.. 0e9b283 100644 -- a/.gitignore +++ b/.gitignore @@-1,3 +1,3 @@-node_modules-package-lock. json -yarn. Lock \ No newline at end of file +# node_modules +# package-lock.json +# yarn.lock \ No newline at end of fileCopy the code
  • git diff --staged: seeHas been staging (add)The documents andSubmitted (commited)What changes have been made to the file.

5. Temporary storage area

1. Join the temporary storage area

  • git add .: Adds all files in the current directory to the staging area
  • git add -u: Add the files that have been tracked to the temporary storage area to be traceable to the parent directory.
  • git add -A: Add all file changes to temporary storage, traceable directory changes, such as new files in the first layer of the directory, now in the directory of the directory directory, thengit add -AThe topmost file changes will be found for staging.

2. Cancel the temporary storage area

  • git reset HEAD [file]: Undoes the specified file added to the staging area
  • git reset HEAD *: Undoes all files added to the staging area, not included in the Mac. Opening file
  • git reset HEAD .*: Unjoins the staging area. Opening file
  • git rm: Add file name or directory or re match to remove temporary memory
  • git rm -f: Forcibly remove, even delete files directly (try not to use it)
  • git rm --cached: Only removes the staging area, not the file

Vi. Submission of documents

1. File submission operations:

  • git commit: Submit the file and fill in the modification information.
  • git commit -m: Enter the modification information when submitting the file.
  • git commit -a: Skips the staging area and submits the file directlygit addoperation

2. The submission is irrevocable but can be replaced

  • git commit --amend: The second commit will replace the first commit, and there will only be one commit

7. Move files (more for renaming)

  • git mv file_from file_to

View the commit history

  • git log: View the submission history.

  • git log -p: View the commit history and discrepancies, which can be very long.

  • git log -p -2: View commit history and differences, and limit log entries to show only the last two commits.

Remote warehouse

  • git clone [url]: Clone the remote repository
  • git remote: View all remote warehouses,originIs the default remote repository name

  • git remote -v: Displays the name and address of the remote repository

  • Git remote add [shortname] [url]: git remote add [shortname

  • Git fetch [shortname]: fetching information that is not available locally in the remote [shortname] repository. For example, native pants will have a master branch and an Origin Master branch. Fetch will pull the master branch of the remote repository to the local Origin master, but not to the master. If necessary, merge manually. However, the pull command updates both the local master and the Origin master. If there is a conflict, it will be directly hinted.

  • Git push [remote] [branch]: remote indicates the name of the remote repository and branch indicates the branch.

  • Git remote show [remote]: remote indicates the name of the remote repository.

  • Git remote rename [newname] [oldname]: rename the repository

  • Git remote remove [name]: Deletes a remote repository

Branch of ten.

1. Create a branch

  • git checkout -b [newbranch]: Clone a new branch from the current branch, equivalent to
git branch [newbranch]
git checkout [newbranch]
Copy the code

2. Switch branches

  • git checkout [branch]: Switches from the current branch to[branch]branch

3. View branches

  • git branch: Displays the current branch.*Represents the current branch

  • git branch -v: Views the last commit of the current branch

4. Merge branches

  • Git merge [branch]: Merges the specified [branch] branch. If a conflict occurs, manually open the conflicting file to resolve it. Once that’s done, you need to temporarily save it with the git add command.

  • Git rebase [branch]: rebase merge. Unlike merge, rebase compares the current branch with the common parent of the specified branch [branch]. Instead of forming a new branch record, place the modified part as a record after the specified branch, that is, the base. Git rebase [basebranch]

  • Git rebase –onto [A] [B] [C]: git rebase –onto [A] [B] [C]: Let C branch merge with A branch record, with the branch record shared by B and C.

5. Delete the branch

  • git branch -d [branch]: Deletes the specified branch, or usesgit branch -D [branch]