Git modify code to View File differences-Remove code-rename a file

Source: Internet
Author: User

Git version 1.9.6

Git code submission hierarchy

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M00/49/CE/wKioL1Qa5-Xyp1LVAADqrDRk-Xk325.jpg "Title =" g.jpg "alt =" wKioL1Qa5-Xyp1LVAADqrDRk-Xk325.jpg "/>

1. modify local code to view differences

Ii. Remove code

Iii. Rename code

1.1 When we modify the local code, we can use the command to see that the file is in the modified State; then we can add the code and then perform commit;

We can see where the code is modified and what the content is modified;

$ git status -s$ echo ‘puts "hello world!"‘ >> hello.rb$ git diff hello.rb

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M00/49/EA/wKioL1Qe2mmwDwKuAAHc0MooazY103.jpg "Title =" d.jpg "alt =" wkiol1qe2mmwdwkuaahc0mooazy103.jpg "/>

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M00/49/E8/wKiom1Qe2uWDT9mYAACWT1yDfwY856.jpg "Title =" d.jpg "alt =" wkiom1qe2uwdt9myaacwt1ydfwy856.jpg "/>

1.2 add this to the staging area and check the file status again

$ git add hello.rb$ git status -s$ git diff hello.rb

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M01/49/E8/wKiom1Qe3AzzYEE3AAF6TcTjgco306.jpg "Title =" d.jpg "alt =" wkiom1qe3azzyee3aaf6tctjgco306.jpg "/>

The file status indicates that the staging area and repository area have changed;

It can be seen that the diff option can be used to view the file changes between the working directory and the staging area;

1.3 Use git diff head to view the file changes between the working directory and repository Areas

$ git diff HEAD hello.rb

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M01/49/EA/wKioL1Qe3h3A7dxtAAFZzNHTlho673.jpg "Title =" d.jpg "alt =" wkiol1qe3h3a7dxtaafzznhtlho673.jpg "/>

1.4 Use git diff -- staged to view the file changes between the staging area and the repository area.

$ git diff --staged hello.rb

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M01/49/EA/wKioL1Qe3zyAT_TjAAFLailWyiY596.jpg "Title =" d.jpg "alt =" wkiol1qe3zyat_tjaaflailwyiy596.jpg "/>

$ Git diff -- staged -- stat hello. RB # output brief information

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M01/49/E8/wKiom1Qe4FDQT_bJAAEHRTcxRDc971.jpg "Title =" d.jpg "alt =" wkiom1qe4fdqt_bjaaehrtcxrdc971.jpg "/>

This is a command for changing the output of a file.

2. Remove code

2.1 Delete the hello. RB file (this step is equivalent to the Add Inverse Operation) to view the File status; commit the result to repository; view the File status;

$ git rm hello.rb$ ls$ git status -s

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M01/49/EA/wKioL1Qe49byh85CAAIHRA9vvto166.jpg "Title =" d.jpg "alt =" wkiol1qe49byh85caaihra9vvto166.jpg "/>

It can be seen that the local file has been deleted when RM is executed;

Execute status. The file status is marked as D, indicating that the deleted state is processed;

$ git commit -m "first del" hello.rb

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M01/49/EA/wKioL1Qe5NqQo4N9AAEYQZ8Ko0k606.jpg "Title =" d.jpg "alt =" wkiol1qe5nqqo4n9aaeyqz8ko0k606.jpg "/>

2.2 If you do not want to delete files in the working directory region and want to delete files in the staging area, run the GIT Rm -- cached command;

$ git rm --cached hello.rb

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M01/49/E9/wKiom1Qe5qWC8R5zAAE64POxIxg994.jpg "Title =" d.jpg "alt =" wkiom1qe5qwc8r5zaae64poxixg994.jpg "/>

After running git status-S, D and ?? What does that mean? D indicates the difference between the staging area and the repository area, indicating that hello. Rb is in the untracked state;

2.3 if you want to restore the hello in the staging area. RB, which can be pulled from repository or submitted from the working directory (if there is no change in the local environment, the new file will be submitted and will not be restored to the previous file );

$ Git reset hello. RB # Pull from Repository

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M02/49/EA/wKioL1Qe6CiAwepPAADACLVTFUc293.jpg "Title =" d.jpg "alt =" wkiol1qe6ciaweppaadaclvtfuc293.jpg "/>

3. Rename the code

3.1 rename the local file readme.txt to readme. md. view the File status and submit it to repository;

$ git mv README.txt README.md$ git commit -m "first rename filename"

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M01/49/EA/wKioL1Qe6cHjUdbdAAIV-QUnl8Q825.jpg "Title =" d.jpg "alt =" wKioL1Qe6cHjUdbdAAIV-QUnl8Q825.jpg "/>

TIPS: When we run the commit command above, we actually performed two steps: delete and submit readme.txt, and submit readme. md;

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M02/49/E9/wKiom1Qe6rLTdz3TAALqluiq7bc972.jpg "Title =" d.jpg "alt =" wkiom1qe6rltdz3taalqluiq7bc972.jpg "/>


In fact, in git, the file name and content can be understood separately (just like the python variable and value); In git, if the content of the two files is the same, it is considered a RENAME;

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M00/49/E9/wKiom1Qe7GDQeNSOAAHySMlU9c0103.jpg "Title =" d.jpg "alt =" wkiom1qe7gdqensoaahysmlu9c0103.jpg "/>



This article is from the "Big Brother" blog, please be sure to keep this source http://lansgg.blog.51cto.com/5675165/1557668

Git modify code to View File differences-Remove code-rename a file

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.