Git novice use must-see guide

  
An example of what can be gained from this guide is that a high school student is working on his (or her) first project and does not need to share code with others. (Specifically, my son, he has written a lot of code, but he has no time to learn a version control tool. This guide is written for him, of course I think others can use it.) For him, It makes sense to use Git. Unlike Subversion, he can easily use Git without a server (as long as he regularly backs up the hard drive, of course, he does.) In a two-minute guide, there is no time to deal with the server, so this guide is especially suitable for situations like my son. Again, the Git usage mentioned in this article is only appropriate for individual developers who regularly back up their hard drives. With a two-minute Git guide plus a backup strategy, you can confidently submit files and know that you can view changes or restore previous versions if you need them. Why is it necessary to learn Git? Well, for developers, the most annoying and time-consuming thing to find is that the programs that worked before can't work now. In this case, it's helpful to be able to see the previous changes and roll back to the previous version. Similarly, being able to fall back to the previous state gives you the freedom to test new methods – there is no problem doing the experiment because you can always come back. If you have the chance, you should definitely learn about staging and branching, as well as pushing and pulling to the remote repository. But what you have to learn below is equally useful. Note: You can use the file path for the file names mentioned below. Pre-use settings If you don't already have git installed, check out the installation guide on the Getting Started page. The first time we use git, we assume that you are working in a folder that is the main folder of your project. The first thing you need to do is use the following command to initialize the folder for Git to use. Git init tells git which file you want to process now that you need to tell git which files to consider. If you have N files, you can add them using git add <file1> <file2> … <fileN>. Or if you want to add all the files in the directory, you can use git add. The period is part of the command and represents the current directory. Submit the changes Next, we need to commit the changes. Any time you want to commit a file or multiple file changes, run git commit <file1> <file2> … <fileN> -m “This is your commit message" or, submit all changes File: git commit -a -m “This is your commit message for all changed files" Make sure your submission contains enough descriptive information so you can figure out which version you want to fall back to. View history Now you need a way to view the old version. In order to view the commit information and the hash value of the commit (a string of numbers representing the version), you can use the following command to output git log as a version of each line --pretty=oneline whose output looks like this: displayed with the hash value of each submission and submit its information dbe28a0a1eba45d823d309cc3659069fc16297e3 4th version I wanted to commit13bbf385e6d1f94c7f11a4cdfa2a7688dfdd84f8 3rda1696f671fb90dc8ea34645a6f851d0ab0152fc2 2nd versio179e59467039c7a7b81f676297415c8e018542a0 first version Note that you can also use git log to output a more verbose information, each version information multiple lines, And you can use git log --pretty=oneline -- <filename> to see changes to a specific file. (Note the second – trailing spaces!) To restore the old version to the previous version of the file, you only need to use the first few numbers of the hash value (to ensure sufficient discrimination): git checkout <hash> -- < ;filename>such as git checkout 179e59467039 -- myfile will roll back the contents of my file named myfile to 179e59467039c7a7b81f676297415c8e018542a0 (here refers to the first commit version of this file). View the changes usually you will not check it first. The file changes back to the old version! To see the difference between the current and historical versions of the file, you need to specify the historical version of the hash value: git diff <hash> -- <filename> You can also compare the difference between the two historical versions: git diff <hash1> < Hash2> -- <filename>One more thing ——optional—— maybe let this article take a minute or more. You may benefit from using only the above functions, you will find that one more thing is very useful. If you don't want to see it now, don't look at —— look for opportunities to see it again next time. Sometimes you don't know which files have been changed. You can find them using the following command: git status This will generate a list of files and their status. For example, a file that has not been ’git add’ will be displayed as `untracked`; if you want to track this file, you need to add it. In my two-minute tutorial, the reason I used this command as an option is that this command might be a bit clumsy. Because it may list a lot of the status of files that you don't care about. For example, if you are programming in the Python language, it will list the .pyc compiled by Python. You definitely want to solve this problem. In order to solve this problem, you need to create a file called `.gitignore` in the directory. For example, if you are using a Python 2.x project, you will want to include (at least) this file: *.pyc Note that .gitignore` can understand * wildcards. If you want to hide a complete directory, you need to add a slash after the folder name. For example, if you use Python 3.x programming, all files will enter a folder called __pycache__, so you need to add __pycache__/to .gitignore. This is this tutorial! Put this tutorial at hand. These are the things you need to know to start using git, as long as you have the habit of regularly backing up your hard drive. If you don't want to remember anything other than submitting a command, just save the tutorial in a bookmark and you can submit it in an unobstructed way, compare the version, and roll back to the old version! Remember, this tutorial is exactly a minimal tutorial, so you can do some useful things with Git. For the powerful features of branching, staging, and sharing code with remote servers and others, be sure to check out the five-minute Git tutorial and even have a chance to see a longer tutorial if you have the chance! This article comes from [System Home] www.xp85.com
Copyright © Windows knowledge All Rights Reserved