Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Git Command Line Command (1)

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

We know that git is a distributed version library, that is, the local repository contains the content used by the development, and everyone is the owner of the local version library, including history and file content. Even if there is no exchange with the remote code base, you can still submit the content to the local repository, and then git push to the remote repository.

You can use git $commit-- help to view the html help documentation for each command, such as git init-- help

one。 Create a local warehouse

Git init can create an empty local repository locally. The common command lines are as follows

Git init [- Q |-- quiet] [--bare] [directory]

-Q |-- quiet: only the warning or error level information is output during the creation process-bare means that the created version library is a naked version library, that is, it does not include a workspace, but a repository of content under the .git directory, which is generally used as a remote repository on the server. Directory is the directory of the local warehouse. Configure the local warehouse

When we have a local repository, we need to configure the repository, the user name and the user's email and other configurations.

The git config command provides three levels of configuration. They are:

-- global: user level. The modified configuration file is in the ~ / .gitconfig file. If it is a windows system, it is under the directory of C:\ Users\ $user name-- system: applicable to the user, and the modified configuration file is in the etc/gitconfig file. If it is a windows system, it is generally modified under the installation directory of git, for example, $GIT_INSTALL_DIR\ mingw64\ etc\ gitconfig--local: applicable to this version of the library. The modified configuration file is in the .git / config file of the local repository, which is also the default scope of git config modification.

When using the git command, the priority of the configuration file is local > global > system. You can use git config-- list-- show-origin to view the file in which each configuration item is located. Set configuration git config [--add] name value-add or modify configuration items. The default scope of use is local warehouse. You can use-- global,-- system to specify the scope. For example, git config user.name fenglxh, git config user.email fenglxh@126.comgit config-- unset name-- cancel the configuration item, and you can also use-- global,-- system to specify the range, 2. Display configuration

Use git config [- l |-- list] to display the configuration

3. Configuration command alias

There are a large number of commands in git, and you can set an alias, that is, an acronym, for commands that we often use, and commands that are long.

The configuration of aliases also requires the use of config commands, such as setting the alias st for git status:

Git config alias.st status-with alias. Beginning git config-- global alias.lg "log-- color-- graph-- oneline-- abbrev-commit"

In this way, when we use it in the future, we can directly use git st to do git status.

three。 Modify local warehouse

The most common way to use versioning is to submit code, but for git, if we modify the content of the file to submit, we must use the git add command before we can use the git commit command to submit to the local repository.

1. Git add

The git add command commits changes to the staging area.

Git add-A-lazy mode that commits all changes in the working directory to the Including deletion, addition, Modify the file git add gameoflife-acceptance-tests/\ * .java-submit all files with java suffixes in a directory to git add * .java-submit files with all java suffixes 2.git rm

The git rm command is to add and delete the temporary storage area, which is basically the opposite of git add. It is a modified temporary storage area.

Git rm-- cached hello-word/README-remove hello-word/README from the staging area git rm-f hello-word/README-remove hello-word/README from the staging area At the same time, delete the file git rm-cached Documentation/*.txt in the working directory and remove 3.git commit from the temporary storage area of all txt files under Documentation.

The git commit command commits changes in the staging area.

Git commit-m "commit message"-commit git commit with commit comments-- allow-empty-m "This is an empty commit"-commit fails when there is no change in the staging area, you can add-- allow-empty runs an empty commit, where the tree objects of the two commits point to the same. 4.git stash

When we modify the contents of the workspace, but can't submit them yet, when we need to update the code, we can store the local changes and use the git stash command. This will save the changes to the workspace (excluding the additions) and switch the contents of the workspace to the submission pointed to by HEAD, which is a clean workspace again.

Git stash-Storage git stash pop-popup Storage git stash list-Show all Stora

The principle of implementation:

When we use the git stash command, a .git / refs/stash file is generated, which contains the sha1 information of the stash. You can view the information about the SHA1 through git cat-file, and you will find that the sha1 is parented with the current SHA1 and workspace submission (a commit object created).

Note: SHA-Stash is the sha1 saved in the .git / refs/stash file. Sha-temp is the submission of the workspace

When we run git stash multiple times, the sha in the .git / refs/stash file always executes the sha corresponding to the most recently executed stash. Save the sha of all stash commands in sequence in the .git\ logs\ refs/stash file

four。 View warehouse 1.git status

Displays the status under the working directory.

When we do not have a working directory change, we execute the following output: $git statusOn branch masterYour branch is up-to-date with 'origin/master'.nothing to commit, working tree clean randomly modifies one of the files, but does not commit the temporary storage area: $git statusOn branch masterYour branch is up-to-date with' origin/master'.Changes not staged for commit: (use "git add..." To update what will be committed) (use "git checkout--..." To discard changes in working directory) modified: pom.xmlno changes added to commit (use "git add" and/or "git commit-a") at this point we commit the changes to the cache, and then check the status, we will see that the staging area has changed. $git statusOn branch masterYour branch is up-to-date with 'origin/master'.Changes to be committed: (use "git reset HEAD..." To unstage) modified: pom.xml We will modify the file at this time, but we will not execute the git add command. $git statusOn branch masterYour branch is up-to-date with 'origin/master'.Changes to be committed: (use "git reset HEAD..." To unstage) modified: pom.xmlChanges not staged for commit: (use "git add..." To update what will be committed) (use "git checkout--..." To discard changes in working directory) modified: pom.xml will find that the pom.xml file has been modified in two places, one is the modification of the temporary storage area, and the other is the modification of the working directory. And the color of the prompt is not the same.

We can use the git status-s command to view the statistical information (the modification of the workspace is in red, and the green font is the modification of the temporary storage area).

2.git diff

The git diff command displays the differences between workspaces, submissions, and staging areas

$git diff-shows the difference between the workspace and the staging area diff-- git a/pom.xml b/pom.xmlindex 0ec4374..3f64500 100644 Methodist-a swap pom.xmlstores @-10line 10 of the document starts the voyage at line 10 SNAPSHOT UTF-8- 1.4 + 1.5 2.6 1.7 test @-178 test 6 + 178 test 12 @ @ ${prima} test + + 178. 2 + test+ $git add pom.xml-submit to the staging area $git diff-cached-- compare the differences between the staging area and the submitted 3.git log

The git log command can view the submitted information.

Git log-1-you can view the most recent submission, and-N represents the last N submission git log-- oneline-N-submission is displayed with one line of information Equal to-- pretty=onelinegit log-- graph-graphically display the submission tree git log-- stat-show the summary information of the submission

Fine output of git log,-- pretty option. Use the-- pretty option to refine the output of all the information about commit.

Git log-- oneline-- equivalent to git log-- pretty=oneline output content is git log-- pretty=short-output content is Git log-- pretty=medium/full/fuller/emailgit log-- pretty=raw temporarily submitted the tree, More complete information such as parent submission

Git-- pretty=format: where string is formattable and supports placeholders. Common placeholders are as follows:

% H: commit hash-submitted SHA%h: abbreviated commit hash-submitted SHA abbreviated form% P: parent hashes-parent submitted SHA%p: abbreviated parent hashes-parent submitted SHA abbreviated form% an: author name-author name% ae: author email%ar: author date, relative%n: newline%%: a raw% -% s: subject-- submit comments

For example: git log-pretty=format: "The author of% h was% an,% ar%nThe title was > >% s

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report