GIT GIT

  • Git init creates a git directory in the current directory, and the current directory becomes a Git repository.

  • Git clone Git repository URL: Copy the HTTP or SSH link to a local git repository.

  • Git add file: Adds a file to the cache that is marked as tracked.

  • Git add. : Caches all files in the current directory, excluding deleted files. Git add only copies the current version of the file to the cache. If you do not git add it again, you will only commit the last git add cache to the repository.

  • Git commit -m “Commit this time” : Commit all file changes in the cache to the current branch of the repository at once.

  • Git commit-am: automatically cache all traced files and submit them to the repository. Often used to skip the Git add step and commit quickly.

  • Git commit –amend “commit now” : commit again. This submission replaces the results of the previous submission. This is especially useful when several files have not been added or the submission information has been incorrectly written. Git add is workspace -> cache, git commit is cache -> repository.

  • Git status: Displays the current status of the repository.

  • Git status -s: a brief introduction to the current status of the repository.

  • Git diff: Compares workspace and cache.

  • Git diff –cached: Compares the difference between a cache and a repository.

  • Git diff files: Compare the difference between a specified file in the workspace and in the cache.

  • Git diff file –cached: Compares the difference between a specified file in the cache and in the repository.

  • Git show: Look at the last commit.

  • Git show HEAD~1: check the penultimate commit.

  • Git show Commit version number: view the specified commit.

  • View staging area commit git ls-files

    • –cached (-c) View files in the staging area. Git ls-files is used by default
    • –midified (-m) View the modified file
    • –delete (-d) View deleted files
    • –other (-o) View files that are not tracked by Git
    • –stage (-s) displays the mode and the Blob object corresponding to the file, so we can retrieve the contents of the file in the staging area.
  • Git rm file: Delete the file from the repository and no longer trace it.

  • Git rm -f: An error occurs when you use git rm to delete a file from the staging area. You can run this command to forcibly delete the file from the cache and version library.

  • Git rm –cached file: Deletes the file from the repository, but leaves it in the workspace and untraceable by Git. This is usually done after an RM file is added to the.gitignore.

  • Git checkout — file: discard workspace changes. This file must be tracked by Git.

  • Git reset HEAD: Discard changes in the cache and roll back to the workspace.

  • Git reset –hard: Resets all files to the last commit state.

  • Git reset –hard HEAD~1: resets the current branch to the second-to-last version.

  • Git reset –hard Commit version number: resets the current branch to the specified version.

  • Git log: Displays commit logs from most recent to most distant. Contains the SHA1 checksum for each submission, the author’s name and email address, the submission time, and submission instructions.

  • Git log –oneline: git log

  • Git log — Decorate: Prints not only git log information, but also extra information such as tags.

  • Git log — The graph not only prints git log information, but also shows when the current branch branches and merges.

  • Git log Branch name: Displays the commit logs of the specified branch.

  • Git log Branch name to view branchA ^ Branch name to ignore branchB: View logs for branchA (excluding branchB)

  • Git tag: View all tags. Note: Labels are not listed chronologically, but alphabetically.

  • Git show

    : displays information about a specified tag.

  • Git tag


    : tags the specified version number.

  • Git checkout

    : switch to the specified tag.

  • Git push –tags: Push tags to remote repositories.

  • Git remote add


    : Shortname is generally origin.

  • Git push


    : push a local branch to a remote repository.

  • Git pull


    : pulls the latest commit from the remote repository and merges it to the specified local branch.

  • Git fetch: Pulls the latest commit from a remote repository, but does not automatically merge branches.

  • Git branch: Lists local branches. The current branch is preceded by an asterisk.

  • Git branch -r: Lists the remote branches.

  • Git branch -a: Lists all branches.

  • Git branch: Create a new branch.

  • Git branch -d branch: Deletes a specified branch.

  • Git branch -v -a: View the last commit of all branches.

  • Git Checkout branch: Switch to a specified branch.

  • Create a local branch and switch git checkout -b branch: Create and switch to the specified branch.

  • Git checkout -b: origin/ git checkout -b: origin/ git checkout

  • Git merge: Merges the specified branch into the current branch. Git status -s can be used to check the conflicting files. The status is UU.

  • Git config –list: lists all configuration information.

  • Git config

    : check the key configuration. For example, git config user.name.

  • Git config –global alias. command alias command: Configure an alias for a command.

  • Git config –global alias.unadd ‘reset HEAD’ :

  • Git config –global alias.st status:

  • Git config –global alias.co checkout

  • Git config –global alias.cm commit

  • Git config –global alias.br branch

  • Git lg: Outputs high level logs

  • Git last: displays the last log

gitignore

Configuration syntax:

  • Directories begin with a slash “/”;
  • Wildcard multiple characters with asterisk “*”;
  • With a question mark “?” Wildcard single character
  • Contains a list of matches for single characters in square brackets “[]”;
  • With exclamation “!” It does not ignore (trace) matched files or directories.