Git version Control tool summary

Source: Internet
Author: User
Tags version control system

1. Install git

Now Linux and Unix including Mac have already come with git, do not own git, in Debian or Ubuntu Linux system execute sudo apt-get install git or sudo apt-get install Git-core can, Mac words can be installed from Xcode inside, run Xcode, choose Menu "Xcode", "Preferences", in the pop-up window find "Downloads", select "Command line Tools", Click "Install" to complete the installation.

Windows can be used msysgit, equivalent to the Windows version of the git,http://msysgit.github.io/download, and then press the default option to install, after the installation, in the Start menu found "git", "Git Bash", Jumping out of something like a command-line window means that Git was installed successfully!


2. Set the user name and password, because Git is a distributed version control system, so each machine must set the user name and mailbox

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

git config--global user.email "[Email protected]"

Note the--global parameter of the git config command, which uses this parameter to indicate that all git repositories on your machine use this configuration, but you can also specify a different user name and email address for a particular repository.

You can also change it directly into the git configuration file.

Locate the. Gitconfig, open the file with vim or another compiler, and you'll see the name and email under [user]

After you modify the save exit.


3. Create a version library

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

Go in that folder to execute the command git init (the meaning of this command is that the folder can be tracked, the contents of the deletion can be tracked, can also be restored)


4. Add all the files under this folder to the warehouse, and then submit all the files to the warehouse and write a description. Like what:

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


5. After each modification of the file (that is, every time you write the code) git add *,git commit-m "Tell me what you did today, where the code is."

If you forget the changes you made last time, you can call git diff or git log or git log--pretty=oneline

To view the last changes, you can also use GIT status to determine the status of the file, such as a few files are not submitted, or a few files are not added


6. Fallback

Each commit git will have a number of numbers to ensure that the corresponding operation, you can treat 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, This means that you can submit n multiple of the number and the corresponding operation content is not wrong, so you can be based on these numbers to fallback, if you need to fallback, you can fall back to the state of the time according to these numbers. The fallback command is git reset, fallback to the last version is git reset--hard head^, the last is Git Reset––hard head^^, can also fall back to the first N versions of Git Reset––hard head~n, can also root According to that string of numbers, Git reset––hard that string of numbers. There is a situation more silent, that is, after the return to find no, and then revert back to the state before the return, this is also achievable, the first method is to find the string of numbers, directly with Git reset––hard that string of numbers. The second method you can use Git reflog to see each of your commands, this command records that there is a string of numbers and the corresponding operation. Finding that string of numbers should be restored.


7. Workspace and Repository

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

This folder contains information about the log and files (those added, those submitted), etc.


8. Undo changes to the workspace

Git checkout--file name. suffix Name

Undo Staging Area modification (staging area is the place after the add, withdraw the words first from staging area, and then cancel the workspace file)

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


9. deleting files

If the file is not added to the staging area, then the direct RM is deleted, if the file is submitted to the repository, only delete in the workspace, Git will remind you that the workspace files and the files in the repository does not match, then either you have to delete the repository, or from the repository to pull a copy, The command to pull over is (the name of the git checkout-file, suffix), and the command to delete the file in the repository is (git rm filename. suffix, remember to submit it again).


This article is from the "Red Corner Antelope" blog, please be sure to keep this source http://2254359459.blog.51cto.com/10776102/1727357

Git version Control tool summary

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.