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 operations of Git

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

Share

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

In this issue, the editor will bring you what are the common operations of Git. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.

Git common commands to create Git version library git init [directory] # create directory version library, if not write, the current directory

This command creates a hidden directory called .git in the directory.

Document submission

Add a file:

Git add filename # added to the next file submitted by commit

Files that have been managed can be submitted using git add-u, so that you no longer have to write the file name

Git status # uses git status to check the status:

On branch master

No commits yet

Changes to be committed

Submitted code

Git commit-m 'comment' # submit the code for all add under the directory

Use git log to view submitted records

View status git statusgit diff filename # View modified lines, change filename

There is a requirement that we need to change test.txt to test.md submission:

Execute git commit

Report an error:

On branch master Changes not staged for commit: deleted: test.txt

Untracked files: test.md

No changes added to commit

It means to delete the test.txt before submitting the test.md

Method 1:

Submit the changed file

Git add test.md

Delete old files

Git rm test.test

Method 2:

Git mv test.txt test.md # this method gives simplicity

View git status:

Git status

On branch master Changes to be committed: (use "git reset HEAD..." To unstage)

Renamed: test.txt-> test.md

It means test.txt is renamed to test.md.

View history

Use the command to view:

Git log [--oneline] # look at the history succinctly

-- onelline: view history succinctly

-n numbers: view recent history

-- all: view the version history of all version branches

-- graph: view the entire warehouse

View details:

Git show commit # commit can be part of the undo code from the local warehouse

Undo submitted code

Git reset-- soft HEAD # undo the code that has been commit

-- soft's softer undo

HEAD undoes the most recent submission, or you can write: HEAD~1

Move the file out of the staging area

Git reset HEAD file name

Please use this undo with caution because you may delete other people's code.

Cancel the code for add

Git checkout--.\ test.md

Use the graphical interface to view

Gitk # is executed in the working directory

Delete a file

Delete the local file first

Then use the command:

Git rm filename git commit-m 'remove redundant files' ignore configuration files

Create a .gitignore file in the repository root directory

Configure: * .txt inside

Branch git branch Branch name # create Branch git branch Branch name for current submission commit hash# create Branch git branch # View Branch git branch-d Branch name # Delete Branch git checkout Branch name # switch Branch git checkout-b Branch name # create and switch Branch git checkout master # switch to backbone git merge Target Branch # merge the target branch into the current branch

Note that commit should be modified before switching branches.

Push the code to the remote warehouse git push-u origin master# and pass the local master branch to the remote master

Origin means GitHub

Get the commonly used commands for git clone git@github.com:liuyanqing1023/xcEduService.git to work together from the remote end

Commit, submit the code

Pull, update the code

Push, push the code remotely

Git directory

There is a .git folder in the git warehouse.

HEAD stores branches that are currently working in the warehouse

Refs

Heads: branch

Tags: tagging commit

Objects: put the object

Toggle branch command: git checkout master

Direct relationship between Git objects

There are three kinds of objects: commit, tree blob

One submission is a commit.

The submitted tree folder is called tree

The file is called blob. As long as the file name is figured out, it is a blob.

Set the configuration at the warehouse level:

# set repository-level configuration, of course, this configuration is not required git config-- local user.name 'admin01' # set user name git config-- local user.email' 395994482@qq.com'# setting email# is used in the repository: git config-- local-- list check whether it is created successfully

The principle of configuration is that the range is small, the range is limited, and the range is large.

History library and temporary storage area

Execute git add files to put the code on the list to be submitted (staging area)

Execute git commit to put the code in the local warehouse (workspace)

Execute git push to put the code in the remote warehouse

These are the common operations of Git shared by the editor. If you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow 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

Internet Technology

Wechat

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

12
Report