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 operation commands of git

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article is a detailed introduction to "what are the commonly used operation commands of git". The content is detailed, the steps are clear, and the details are properly handled. I hope this article "what are the commonly used operation commands of git" can help you solve your doubts. Let's go deeper and learn new knowledge together with the ideas of the small editor.

I. Using Git to clone projects

Right-click Git Bash Here to configure your account and email.

git config --global user.name 'account name'git config --global user.email 'mailbox'

Next, clone the project locally using clone

git clone HTTP path/SSH path

When the progress is finished, you can find that the project is already in the local file, which has proved that the cloning is successful.

Here are some common commands for Git beginners.

View remote repository: git remote -v

Add remote repository: git remote add [name] [url]

Remove remote repository: git remote rm [name]

Modify remote repository: git remote set-url --push[name][newUrl]

Pull remote repository: git pull [remoteName] [localBranchName]

Push remote repository: git push [remoteName] [localBranchName]

II. Common commands for Git branch operations

View local branch: git branch

View remote branch: git branch -r

Create a local branch: git branch [name] ---At this time, it is necessary to note that when using this command, the new branch will not automatically switch to the current branch after it is created

Switch branch: git checkout [name]

Create a new branch and switch to it immediately: git checkout -b [name]

Delete branch: git branch -d [name] ---Note: The-d option can only delete branches that have participated in the merge, and branches that have not been merged cannot be deleted. If you want to forcibly delete a branch, you can use the-D option

Merging branches: git merge [name] ---Merges the branch named [name] with the current branch

Create remote branch (local branch push to remote): git push origin [name]

Remove remote branch: git push origin :heads/[name]

III. Common commands for Git submission code operation

View file status: git status

Add file: git add * ---Note item * here represents all, if you want to specify add, you can change the * sign to the specified file.

Submit file: git commit -m 'Submit description'---At this time, the commit code has not been submitted to the remote issue, but in the buffer of the local issue.

Push file: git push origin master ---master here is the main branch, if you need to push to the branch, you can change master to the branch name.

If you want to ignore some files or folders and don't want to submit them, create a file named ".gitignore" under the root directory of the repository, write the unwanted file name or folder name, and occupy one line per file or folder, such as the following:

document A

file B

file C

can

IV. Common commands for Git version operation

View Version: git tag

Created version: git tag [name]

Delete version: git tag -d [name]

View remote version: git tag -r

Create remote version (local version push to remote): git push origin [name]

Remove remote version: git push origin :refs/tags/[name]

V. Common commands for Git submodule operation

Add submodule: git submodule add [url] [path]

Initialize submodule: git submodule init ---Note: Run only once when checking out the repository for the first time

Update submodule: git submodule update ---Note: You need to run it every time you update or switch branches

To delete a subtemplate, the following steps are required:

First, type git rm --cached [path] in Bash Here.

Second, edit the ".gitmodules" file and delete the relevant configuration nodes of the submodules.

Third, edit the ".git/config" file and delete the relevant configuration nodes of the submodule.

Finally, manually delete the remaining directories of submodules

VI. Common commands for Git to delete files

Delete file: git rm file.txt

submit delete file: git commit -m "rm file"

Push file: git push origin master ---master here is the main branch, if you need to push to the branch, you can change master to the branch name.

Note: Delete command please use caution

Recover local files that have been deleted by mistake: git checkout ----overwrite local files with temporary files

VII. Common commands for Git rollback operation

Search Log: git log

Rollback to a committed record: git reset commit_id

Roll back to this commit record: git reset --hard commit_id

git push origin HEAD --force

Mistaken deletion recovery needs to be rolled back to the error commit_id, or a commit record is deleted by mistake, which can be recovered by the following code:

git relog ---copies the hash value of the operation to be recovered

git reset --hard hash ---Change hash to hash value of history to be restored

Note: When deleting a commit, it is best not to use git reset to roll back the remote repository, because others will also roll back their local repository to the previous version with git pull, which is easy to make errors and increase unnecessary workload.

git rebase: Two branches are not on a line, use this command when you need to perform a merge operation.

If a commit in the middle needs to be deleted, it can be done by git rebase command, as follows:

git log

git rebase -i commit_id ---Replace commit_id with copied value

Enter Vim editing mode and change `pick` before the commit to be deleted to `drop`.

Save and exit Vim

VIII. Common commands for conflict resolution operations

View conflict content: git diff

Manual conflict resolution: git add or git add -A

If you are still in the rebase state, you can use git rebase --continue to repeat the previous steps until the word applying appears when the rebase is complete.

Last Git Push submission

Give up a commit: git revert

Undo merge node commit: you need to add-m instruction, such as git reverse commit_id -m 'description'

Read here, this article "What are the common operation commands of git" has been introduced, want to master the knowledge points of this article also need to be used by yourself to understand, if you want to know more about the relevant content of the article, welcome to pay attention to the industry information channel.

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

Development

Wechat

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

12
Report