Android Development Learning Path-git's minimalist tutorial?
Source: Internet
Author: User
<span id="Label3"></p><p><p>Git is a code versioning tool that allows us to have multiple versions of a project so that we can modify our code as we like, and if something goes wrong, you can fall back to a submission Point. If you're still updating your code with piles of comments, you can try git, after all, it's not Hard.</p></p><p><p>The common git operation is not much, understand this process is Ok.</p></p><p><p>※ It's easy to install git, so don't say it here. No money to buy mac, so ...</p></p><p><p>Simple process: <strong>initialization, modify file, Add to staging area, commit changes</strong> , fallback</p></p><p><p>After installation, you need to set up a username and a mailbox, right-click git Bash here in the desktop and open a small black window</p></p><p><p></p></p><p><p>Enter the following command to set it up:</p></p><pre><pre><span style="color: #800000;">"</span> <span style="color: #800000;">XXX</span> <span style="color: #800000;">"</span></pre></pre><pre><pre><span style="color: #800000;">"</span> <span style="color: #800000;">[email protected]</span> <span style="color: #800000;">"</span></pre></pre><p><p>① initialization: git init</p></p><p><p>First into the project directory, where the demo is in the D:\GitDemoProject directory, the project is temporarily empty, you can also use studio directly to build a HELLOWORLD.</p></p><p><p>Right-click the project root and choose Git Bash here to open the command window.</p></p><p><p>All of our commands are entered in this WINDOW.</p></p><p><p>Then enter: git init and then enter, there will be the following prompt:</p></p><pre><pre><span style="color: #000000;"></span><span style="color: #0000ff;">inch</span> d:/gitdemoproject/.git/</pre></pre><p><p>This completes our initialization, and A. Git folder is created under the Project.</p></p><p><p>② Creating a file</p></p><p><p>If you are familiar with linux, you can use this bash to touch a file directly, we right-click here to create a test.txt file and Enter: Hello Git</p></p><p><p>Here is a command: git status, which will be prompted with the following in the bash Input:</p></p><pre><pre><span style="color: #000000;">$ git statuson branch masterinitial commituntracked files: </span> <span style="color: #800000;">"</span> <span style="color: #800000;">git add <file>, ...</span> . <span style="color: #800000;">"</span> <span style="color: #0000ff;">inch</span> what'll be <span style="color: #000000;">committed) </span> <span style="color: #800000;">"</span> <span style="color: #800000;">git add</span> <span style="color: #800000;"></span> to Track)</pre></pre><p><p>The last line prompts us that no files were added to the tracking state, but a newly created non-tracked file was Found.</p></p><p><p>③ Add to Staging area</p></p><p><p>The new files above are outside of staging area, and these files will not be controlled by git, which is the fact that our git has not actually saved any data about this File. We need to let git know that this file needs to be tagged and if it has any modifications, tell Me.</p></p><p><p>Commands added to staging area: git add file name</p></p><pre><pre>$ git add test.txt</pre></pre><p><p>Check the status again at this time:</p></p><pre><pre><span style="color: #000000;">$ git statuson branch masterinitial commitchanges to be committed: </span> <span style="color: #800000;">"</span> <span style="color: #800000;">git rm--cached <file></span> <span style="color: #800000;">"</span> to <span style="color: #000000;">Unstage) </span> <span style="color: #0000ff;">file</span>: test.txt</pre></pre><p><p>The status of our files is no longer untracked.</p></p><p><p>④ Commit Changes</p></p><p><p>Command: git commit-m "xxx"</p></p><p><p>XXX refers to the submission of the message, with a short and concise words to describe the content of the word submitted can help us to quickly version Switching.</p></p><pre><pre><span style="color: #800000;">"</span> first <span style="color: #800000;">Commit</span> <span style="color: #800000;">"</span> <span style="color: #000000;">[master (root</span>-<span style="color: #000000;"></span><span style="color: #800080;">1</span><span style="color: #0000ff;">file</span><span style="color: #800080;">1</span> insertion (+<span style="color: #000000;"></span><span style="color: #800080;">100644</span> test.txt</pre></pre><p><p>This time, we have completed a Submission. currently, the current version of the entire project has been saved by git and can be rolled back when Needed.</p></p><p><p>Now look at the Status:</p></p><pre><pre><span style="color: #000000;">$ git Statuson branch masternothing to commits, working directory clean</span></pre></pre><p><p>Tip We don't have anything to commit, this state will change only if the tracked file Changes.</p></p><p><p>Let's try it out!</p></p><p><p>We open the Test.txt file and modify it to read: Hello Android</p></p><p><p>Then re-view the Status:</p></p><pre><pre> <span style="color: #000000;">$ git statuson branch masterchanges not staged </span> <span style="color: #0000ff;">for </span> <span style="color: #000000;"> commit: (use </span> <span style="color: #800000;" "< span> <span style="color: #800000;">git add <file> ... </span> <span style="color: #800000;"> "</span> <span style="color: #000000;" "to update what'll be committed) (use < span> <span style="color: #800000;"> "</span> <span style="color: #800000;">git checkout-<file> ... </span> <span style="color: #800000;"> </span> to discard changes <span style="color: #0000ff;">in </span> <span style="color : #000000; "> working Directory) Modified:test.txtno changes added to commit (use </span> <span style="color: #800000;"> "<span style="color: #800000;">git add </span> <span style="color: #800000;"> "</span> and/or <span style=" color: # 800000; "> "</span> <span style=" color: #800000; ">git commit-a </span> <span style=" color: #800000; ">" </span>) </span></span></span></pre></pre><p><p>Now we are told that a file has changed (modified) and needs to be re-added to staging area before it can be submitted.</p></p><p><p>But don't worry, we'll create a new file named readme.txt, no need to add any Content.</p></p><p><p>Run git status again this time to view the Status:</p></p><pre><span style="color: #000000;"><span style="color: #000000;">$ git Statuson branch masterchanges not staged</span></span><span style="color: #0000ff;"><span style="color: #0000ff;"></span> for</span><span style="color: #000000;"><span style="color: #000000;">Commit: (</span> use</span><span style="color: #800000;"><span style="color: #800000;">"</span></span><span style="color: #800000;"><span style="color: #800000;">git add <file>, ...</span> .</span><span style="color: #800000;"><span style="color: #800000;">"</span></span><span style="color: #000000;">To update what'll be <span style="color: #000000;">committed) (</span> use</span><span style="color: #800000;"><span style="color: #800000;">"</span></span><span style="color: #800000;"><span style="color: #800000;">git checkout--<file>, ...</span> .</span><span style="color: #800000;"><span style="color: #800000;">"</span></span>To discard changes<span style="color: #0000ff;"><span style="color: #0000ff;">inch</span></span><span style="color: #000000;"><span style="color: #000000;">working Directory) modified:test.txtUntracked files: (</span> use</span><span style="color: #800000;"><span style="color: #800000;">"</span></span><span style="color: #800000;"><span style="color: #800000;">git add <file>, ...</span> .</span><span style="color: #800000;"><span style="color: #800000;">"</span></span>To include<span style="color: #0000ff;"><span style="color: #0000ff;">inch</span></span><span style="color: #000000;">What would be is <span style="color: #000000;">committed) readme.txtno changes added to commit (</span> use</span><span style="color: #800000;"><span style="color: #800000;">"</span></span><span style="color: #800000;"><span style="color: #800000;">git add</span></span><span style="color: #800000;"><span style="color: #800000;">"</span></span>and/or<span style="color: #800000;"><span style="color: #800000;">"</span></span><span style="color: #800000;"><span style="color: #800000;">git commit-a</span></span><span style="color: #800000;"><span style="color: #800000;">"</span></span>)</pre><p><p>As you can see, the new file status is untracked, this time, we need to add these two files to staging area before we can commit, the command to add these two files directly to staging area is git add.</p></p><pre><pre>$ git Add.</pre></pre><p><p>This command adds all the files in the directory to the staging Area.</p></p><p><p>Then check the Status:</p></p><pre><pre><span style="color: #000000;">$ git Statuson branch masterchanges to be committed: </span> <span style="color: #800000;">"</span> <span style="color: #800000;">git reset HEAD <file></span> <span style="color: #800000;">"</span> to <span style="color: #000000;">Unstage) </span> <span style="color: #0000ff;">file</span> <span style="color: #000000;">: readme.txt modified: test.txt</span></pre></pre><p><p>This time can be a second commit, we directly input: git commit command, note do not input-m "xxx", the window will jump to the following places:</p></p><p><p></p></p><p><p>Here is a bit of vim, this file is actually used to represent the content of the file submission, all the lines beginning with the # are ignored, so we can write another line of our submission Information. If you don't know what to do here, you can use-m directly instead.</p></p><p><p>Revise and save well to return to the original place:</p></p><pre><pre><span style="color: #000000;"></span><span style="color: #800080;">2</span> <span style="color: #800080;">1</span> <span style="color: #800080;">1</span> deletion (-<span style="color: #000000;"></span><span style="color: #800080;">100644</span> Readme.txt</pre></pre><p><p>⑤ fallback</p></p><p><p>Suppose we now find that the second commit is problematic, and we need to go back to the place where we first submitted it, how do we do it?</p></p><p><p>Here we can use the git reset command, which requires us to fill in a value that represents the fallback point in order to confirm the fallback Location. This value can be viewed through git log:</p></p><pre><span style="color: #000000;"><span style="color: #000000;">$ git logcommit ea017b63e4043e7750efd2eb39f39d5668b69ec4author:fndroid</span></span><<span style="color: #800080;"><span style="color: #800080;">1603808949</span></span>@qq .com><span style="color: #000000;"><span style="color: #000000;">Date:fri</span></span><span style="color: #800080;"><span style="color: #800080;"></span> a</span> <span style="color: #800080;"><span style="color: #800080;"></span> +</span>:<span style="color: #800080;"><span style="color: #800080;"></span> -</span>:<span style="color: #800080;"><span style="color: #800080;">Geneva</span></span> <span style="color: #800080;"><span style="color: #800080;"></span> .</span>+<span style="color: #800080;"><span style="color: #800080;">0800</span></span><span style="color: #000000;"><span style="color: #000000;">Create Readme.txt and modified the Test.txtcommit 5b59dc7a5aa1338b06f107dea6492842a5c3286dauthor:fndroid</span></span><<span style="color: #800080;"><span style="color: #800080;">1603808949</span></span>@qq .com><span style="color: #000000;"><span style="color: #000000;">Date:fri</span></span><span style="color: #800080;"><span style="color: #800080;"></span> a</span> <span style="color: #800080;"><span style="color: #800080;"></span> +</span>:<span style="color: #800080;"><span style="color: #800080;"></span> geneva</span>:<span style="color: #800080;"><span style="color: #800080;"></span> -</span> <span style="color: #800080;"><span style="color: #800080;"></span> .</span>+<span style="color: #800080;"><span style="color: #800080;">0800</span></span><span style="color: #000000;">first <span style="color: #000000;">Commit</span></span></pre><p><p>As you can see, we submitted two times, each time after the commit there is a string of long point-in-time hash value, we can fall back to the commit point based on this hash value:</p></p><pre><pre>$ git reset--hard 5b59dc7a5aa1338b06f107dea6492842a5c3286dhead are now at<span style="color: #000000;">5b59dc7 First commit</span></pre></pre><p><p>At this point, back to the root of your project, you can see that the Readme.txt file we created is gone, and that the contents of the Test.txt file are reverted to Hello Git.</p></p><p><p></p></p><p><p>※ The fallback <strong>operation discards all submissions after the fallback point, so please be cautious. </strong></p></p><p><p>here, the entire process has gone, we have been able to control the project more than one Version.</p></p>
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