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

What are the commands commonly used in Git?

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

This article mainly explains "what are the commonly used commands in Git". Friends who are interested may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "what are the common commands of Git?"

Git common commands 1, basic commands

Set LESSCHARSET=utf-8-IDE Terminal garbled (the operation git window that comes with idea)

Git clone branch name-Clone the branch locally

Git stash-temporarily put the modification in the temporary storage area, and change something in branch a. If you want to cut to branch b first, you can use this command first.

Git stash pop-pops up from the staging area, switches from b to a, and restores the changed ones with this command

Git checkout branch name or file name-switch to branch

Git pull-pull the latest file (update)

/ / these three are usually used together to submit code to a remote branch

Git add file name-add a file (for subsequent submissions)

Git commit-m "submit remarks"-submit files to local branch

Git push-push to remote branch

Git cherry-pick version number-this can be used when merging a version of branch an into version b

2. After adding extra files, undo the addition if you have already add but not commit

Git reset HEAD file name-undo a file

Git reset HEAD-undo all

3. Return the version number when commit has not been push.

Git reset-- which version number does mixed want to fallback to (the local code is still retained)

Git reset-- which version number does hard want to fallback to (local code is not reserved)

4. Pull back and cancel after push

If you have push the code to the remote repository, you also want to roll back the code from the remote repository to a specified version, and the local and remote branch code will be consistent.

You need to use the revert command.

Git revert is used to reverse the submission, and the revert command requires that the work tree must be clean.

Git revert uses a new submission to eliminate any changes made by a historical submission.

After revert, your local code will be rolled back to the specified historical version, and you can update the online code after git push. (it's not a conflict problem like reset.)

To use revert, you need to find the unique commit identification code of the version you want to roll back. You can use git log or in the web environment history submission record built by adgit.

Git revert c011eb3c20ba6fb38cc94fe5a8dda366a3990c61

Usually, the first few bits can be git revert c011eb3

Git revert is the commit before rolling back and forth with a new commit

Git reset deletes the specified commit directly

The effect seems to be the same, but in fact it is completely different.

As we said above, if you have push to the online code base, after reset deletes the specified commit, your git push may cause a lot of conflicts. But revert won't.

If the existing branch and the history branch need to be merged in the future, the code of the reset recovery part will still appear in the history branch. However, the commit submitted to the revert does not appear in the history branch.

Reset deletes the specified commit in the normal commit history, when the HEAD moves backwards, while revert commit again in the normal commit history, but reverse commits, and his HEAD is always forward.

5. Alias simplified git command

Git config-- global alias. Alias original command

Such as:

Git config-global alias.st status

Git config-global alias.ck checkout

Git config-global alias.ct commit

You can use the simplified command directly when you use it later, git st.

For code managers, you have to close many versions every day, for example, if you execute the git cherry-pick version number to simplify cherry-pick to cp, you will type a lot less letters.

6. View the submission log record

In general:

1. Git log-View all submitted log

You can add parameters to achieve different log display effects.

2. Git log-- author user name-- query the records submitted by a user

Effect:

3. Git log-- author user name-- grep "keyword" displays a record submitted by a user containing a keyword

Effect:

4. Optional command-if reverse does not add this, the default is in chronological order, the latest submission will be displayed first, and the earliest submission will be displayed if you add this parameter.

5.-- oneline simplified display is simplified on the basis of 3, showing only one line, and the version number is simplified.

Effect:

6. More complicated

Git log-graph-pretty=format:'%Cred%h%Creset -% C (yellow)% d%Creset% s% Cgreen (% cr)% C (blue)% Creset'-- abbrev-commit-- date=relative

7. Git to check the warehouse address

We have too many code repositories, or use it for a long time, and we haven't had clone for a long time, so it's easy to forget clone's URL. At this time, we can use this command.

Git remote-v

View the URL of the current warehouse

At this point, I believe you have a deeper understanding of "what are the commands commonly used in Git?" you might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

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