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

Summary of GIT version control tools

2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

1. install GIT

Now Linux and Unix, including MAC, some have their own git. If they don't have their own git, you can execute sudo apt-get install git or sudo apt-get install git-core under Debian or Ubuntu Linux system. MAC can be installed from Xcode. Run Xcode, select menu "Xcode"->"Preferences", find "Downloads" in the pop-up window, select "Command Line Tools", click "Install" to complete the installation.

For Windows, you can use msysgit, which is equivalent to the Windows version of Git, http://msysgit.github.io/download, and then install it according to the default options. After the installation is complete, find "Git"->"Git Bash" in the Start menu, and pop up something similar to the command line window, indicating that Git has been successfully installed!

2. Set username and password, because git is a distributed version control system, so each machine must set username and mailbox

git config --global user.name "Your Name"

git config --global user.email "email@example.com"

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

You can also modify it directly into the git configuration file

Find.gitconfig, open it with vim or another compiler, and you'll see the name and email below [user].

Save and exit directly after modification.

3. Create a repository

Find a free place at random, create a directory, put all the code into it,(should say find the folder where your code is located, it is best not to have Chinese in the path)

Go into that folder and execute the command git init (the meaning of this command is that this folder can be tracked, and the things inside can be tracked, deleted, and restored)

4. Add all the files under this folder to the repository, submit all the files to the repository, and write a description by the way. For example:

git add filename. suffix, or git add * then commit all files, git commit -m"operation details, changed or deleted something equivalent to log"

5. Every time you change a file after that, git add *,git commit -m"Tell me what you did today, where you got the code."

If you forget your last change, you can call git diff or git log or git log --pretty=oneline.

To see the last change, you can also use git status to determine the status of the file, such as how many files have not been committed, or how many files have not been added.

6. Retreat

Each commit git will have a string of numbers to ensure that it corresponds to an operation, you can think of it as a serial number or version number, execute git log or git log --pretty=oneline you will see these numbers, each time the number is different, which means that you can commit N times where the number and corresponding operation content are not wrong, so you can use these numbers to roll back, if you need to roll back, you can use these numbers to roll back to the current state. The command to go back is git reset, the previous version is git reset --hard HEAD^, the previous version is git reset --hard HEAD^^, you can also go back to the first N versions git reset --hard HEAD~N, or you can go back according to that string of numbers, git reset --hard. There is also a situation that is even more speechless, that is, after retreating, it is found that it is not working, and then restore the state before retreating. This can also be realized. The first method is to find that string of numbers and directly use git reset --hard that string of numbers. The second way you can check each command you have is by git reflog, which records the string of numbers and the corresponding operation. Finding that string of numbers should restore it.

7. Workspaces and version libraries

The workspace is this directory where all files can see changes, the folder where your code is stored, and the repository is a hidden folder in the current directory named.git.

This folder contains information about logs and the status of files (those added, those committed) and so on.

8. Undo workspace modifications

git checkout --filename. suffix name

Undo the changes in the temporary area (temporary area is the place after add, if you undo it, take it out of the temporary area first, and then undo the file in the workspace)

git reset HEAD file, git checkout --filename. suffix name

9. delete files

If the file is not added to the temporary storage area, then it can be deleted directly rm, if the file is submitted to the version library, only deleted in the workspace, git will remind you that the file in the workspace does not match the file in the version library, then either you also delete the version library, or pull a copy from the version library, pull the command is (git checkout -file name. suffix), the command to delete files in the repository is (git rm filename. And remember, you have to submit it again.)

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