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 common commands of Git in linux

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

Share

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

Editor to share with you what Git commands are commonly used in linux. I hope you will get something after reading this article. Let's discuss it together.

Important concepts of Git

Master head

Each time a submission is submitted, Git strands them into a timeline, which is a branch. In Git, there is a branch called the main branch, the master branch. Strictly speaking, HEAD does not point to the commit, but to the master,master points to the commit, so HEAD points to the current branch.

At the beginning, the master branch is a line, and Git points to the commit of * * with master, and then to master with HEAD, you can determine the current branch and the submission point of the current branch.

Each time you commit, the master branch moves forward so that as you continue to commit, the line of the master branch gets longer and longer:

When we create a new branch, such as dev, Git creates a new pointer called dev, which points to the same commit as master, and then points HEAD to dev, indicating that the current branch is on dev.

From now on, changes and commits to the workspace are for the dev branch, such as after a new commit, the dev pointer moves forward, while the master pointer remains unchanged.

If our work on dev is done, we can merge dev into master. How does Git merge? The easiest way is to point the master directly to the current commit of dev and complete the merge.

After merging branches, you can even delete dev branches. To delete a dev branch is to delete the dev pointer. After deleting it, we have only one master branch left.

Temporary storage area

Workspace Workspace: this is the directory you can see on your computer, the folder where your code is placed. Real-time, all changes to the file will be mentioned here immediately.

Version library: the workspace has a hidden directory. Git, which is not a workspace, but a version library of Git.

After the staging area Index / Stage:git add, the current changes to the file will be saved to this area

After the local warehouse Repository:git commit, changes to the files in the current temporary storage area will be submitted to the local warehouse

Remote warehouse Remote: the remote warehouse name is generally called origin. After git push, the commit in the local warehouse that takes precedence over the remote warehouse will be push to the remote warehouse.

Download and install

Download from git official website

Initialization

Initialization parameter

$git config-- global user.name "your name" $git config-- global user.email "your email address"

Because Git is a distributed version control system, every machine must report itself: your name and Email address.

Note the-global parameter of the git config command, which means that all Git repositories on your machine will use this configuration. Of course, you can also specify a different user name and Email address for a warehouse.

Initialize the local warehouse

$git init

SSH key generation

$ssh-keygen-t rsa-C "your email address"

Clone code

/ / Clone master branch $git clone / / specify the branch name of the clone $git clone-b

.gitignore effective measures

/ / first delete the local cache (change to a non-track state) $git rm-r-cached. / / and then submit $git add. $git commit-m'update. Gitignore'

View various statu

/ / View current status (branch name, any changes, conflicts, contents in the workspace staging area, several commit, etc.) $git status / / View local warehouse submission history $git log / / View local warehouse submission history, concise version $git log-- pretty=oneline / / View command history $git reflog

Branch

/ / View branch: $git branch-a / / create local branch: $git branch / / switch local branch: $git checkout / / create + switch local branch: $git checkout-b / / merge a branch into the current branch: $git merge / / push the local branch to the remote $git push origin / / based on the remote branch Create a local branch $git checkout-b origin/// to delete the local branch: $git branch-d / / delete the remote branch. Pushing an empty local branch to a remote branch is equivalent to deleting the remote branch $git push origin:

Update and submit code

A new file, or change. At first, only your workspace existed. When you use git add, Git caches the change and tracks it. When you use git commit, your changes will be submitted to the warehouse.

/ / cache all changes $git add-- all / / cache individual file changes $git add / / submit to the local warehouse $git commit-m / / update the local code $git pull origin / / push the local commit to the remote $git push orign

Revocation

/ / undo changes to a file in the workspace $git checkout [file] / / undo changes to all files in the workspace $git checkout. / / resets the specified file for the staging area, consistent with the previous commit. However, the change did not disappear, but the change called back to the workspace $git reset [file] / / reset the staging area and the workspace, consistent with the previous commit. $git reset-- hard / / resets the pointer of the current branch to the specified commit and resets the staging area. However, the change did not disappear. Instead, the change called back to the workspace $git reset [commit] / / resets the HEAD of the current branch to the specified commit, and resets the staging area and the workspace, consistent with the specified commit. $git reset-- hard [commit] / / resets the current HEAD to the specified commit, but leaves the staging area and workspace unchanged $git reset-- keep [commit] / / temporarily stores uncommitted changes in stash, and pops up $git stash $git stash pop git review later

Code review uses the gerrit system, and git uses the git review (default is master) command to perform review operations.

Rules

Pull the remote code before submitting the reivew to ensure that the submission used to be a * code, and that any conflicts need to be merged locally.

A single functional change is put into a commit and submitted to a reivew.

Special circumstances

What if review fails?

First go back to the commit to be modified

$git reset-soft

Continue to modify the file you want to change. Modify the add cache file and execute the

$git commit-amend

Merge the newly produced changes into the last change and continue to execute git review

What if I have made multiple submission commits?

If multiple submissions are related, merge this submission into one submission

/ / query the commit submitted by * and remember id. $git log / / change the base operation $git rebase-I / / the pop-up interface lists all the submitted records from * * commit to the present / / change the 'pick'' at the beginning of each column to's submission, leaving only the 'pick'' in the column. / / after saving the changes, the system will automatically merge these commits into a commit. / / if you encounter a conflict, you need to resolve it manually. After the merge conflict, continue to change the base until all commits are merged. $git rebase-continue

What if more than one commits is submitted in the review and one of the commit fails the review (including no change id generated in a previous commit)? A commit is generated one review at a time. If the previous review fails, the subsequent review will not be submitted. The previous review must be passed before the subsequent review can be submitted.

/ / query the commit id corresponding to the failed review (there is a record in gerrit) / / return to the previous node of this commit, notice that there is a ^ $execute git rebase-I ^ / / modify and cache the file to be submitted after $git commit-- amend / / return to head $git rebase-- continue / / submit an update to the old review $git review has finished reading this article I believe you have a certain understanding of "what are the common Git commands in linux". If you want to know more about it, you are welcome to follow the industry information channel. Thank you for your reading!

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

Servers

Wechat

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

12
Report