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

Introduction to Git Foundation (7) Git undo Operation and remote Warehouse Management

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

Share

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

Undo operation:

Note: some undo actions of Git are irreversible. This is one of the few places where previous jobs are lost due to operational errors in the process of using Git

Cancel temporary files

Git add a.py b.py

Git status

On branch master

Changes to be committed:

(use "git reset HEAD..." To unstage) # prompt how to undo

Modified: a.py

Modified: b.py

Git reset HEAD b.py # cancel staging b.py

Unstaged changes after reset:

M b.py

Git status

On branch master

Changes to be committed:

(use "git reset HEAD..." To unstage)

Modified: a.py

Changes not staged for commit:

(use "git add..." To update what will be committed)

(use "git checkout--..." To discard changes in working directory) # prompt to undo changes to the file

Modified: b.py

Undo changes to the file

Git checkout b.py

Git status

On branch master

Changes to be committed:

(use "git reset HEAD..." To unstage)

Modified: a.py

Git checkout-- [file] is a dangerous command. If you execute this command, any changes you make to that file will disappear.

Remote warehouse:

A remote repository is a repository of versions of your project hosted on the Internet or other networks. There can be multiple remote repositories, some of which are read-only to you, while others can be read and written.

Managing remote repositories includes understanding how to add remote repositories, removing remote repositories, managing different remote branches and defining whether they are tracked, and so on.

View remote warehouse

Git remote # View all current remote repositories

Origin # origin is the default name of the warehouse server that Git cloned for you.

-v option to display the abbreviation of the remote warehouse and its corresponding URL

Git remote-v

Origin https://github.com/libgit2/libgit2 (fetch)

Origin https://github.com/libgit2/libgit2 (push)

Add remote warehouse

Git remote add # add a new remote Git repository and specify an abbreviation

Git remote add test https://github.com/huyuan1999/17-10-22.git # add remote warehouse

Git remote-v

Origin https://github.com/libgit2/libgit2 (fetch)

Origin https://github.com/libgit2/libgit2 (push)

Test https://github.com/huyuan1999/17-10-22.git (fetch)

Test https://github.com/huyuan1999/17-10-22.git (push)

You can now use test instead of the entire URL on the command line

Git fetch test # pull information from the remote repository (information that is not available in the local working directory)

Grab and pull from remote warehouse

Git fetch [remote-name] # pull data from a remote warehouse (branches are not automatically merged)

If you use the clone command to clone a repository and add it as a remote repository, origin is abbreviated by default. So git fetch origin will grab all the data of the new push after cloning.

Git pull [remote-name] # automatically crawls and then merges the remote branch to the current branch

By default, git clone automatically sets the local master branch to track the cloned remote warehouse master branch. Running git pull usually grabs data from the cloned server and automatically attempts to merge to the current branch.

Push to remote warehouse

Git push [remote-name] [branch-name] # push the specified branch to the server

Git push test master # git uses github as the remote warehouse server by default. If you want to push to the remote warehouse, you need to have a corresponding account and password.

View remote warehouse

Git remote show test

* remote test # Local abbreviation

Fetch URL: https://github.com/huyuan1999/17-10-22.git

Push URL: https://github.com/huyuan1999/17-10-22.git

HEAD branch: the branch where master # is located

Remote branch:

Master tracked # Mastering tracking

Local ref configured for 'git push':

Master pushes to master (up to date)

Removal and renaming of remote warehouse

Git remote rename test hu # rename

Git remote

Origin

Hu

Git remote rm hu # remove

Git remote

Origin

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