git use case analysis

Source: Internet
Author: User

Document the problems that James has encountered in his work:

1. Submit the. cfg file in the app directory, at which time git and Gerrit are used together;

2. Additional submissions to the revised document;

3. View all branches of the current directory, including: local branch and Remote branch;

4. Create a branch from the remote branch and view the correspondence between all branches and the remote branch;

5. Save the changes to the current branch before switching the branch, and revert the changes when returning;

6. In the local file system, establish the remote repository and clone the warehouse, and submit the update in the local warehouse;

7. Delete the server-side file contents and submit the deletion changes;

Analysis of the above problems:

1. Submit the. cfg file in the app directory, using scenarios: Git and Gerrit, and know that Gerrit is a tool for code auditing.

Submit the Code and file (which is the content under the app folder) and need to enter the. Git directory to perform the following steps:

1. (First you need to see which files have been changed) git add assets/cfg_k86s7_kst-t5.cfg

2. Git ST//View the Add command execution results (priority to detect if the repository is updated) git fetch//detect if there is an update, if there is an update (add new code), you need to perform git pull first

3. Git ci-m "add cfg_k86s7_kst-t5.cfg"//commit is equivalent to submitting a command;

4. Git LG//view log, check the execution results of this command;

5. Git push Origin Head:refs/for/master//submit to server, need to be audited!

6. Check if push to remote branch, view gerrit2.y/server;

The question that most needs to be answered is: Why do I need to use GIT push Origin head:refs/for/master. Since the use of Gerrit as a code audit tool, you need to follow the push specification, and the above submission instructions are the specifications for submitting the audit.

2. Append commit to commit that has been push to the Gerrit server.

1. MV assets/cfg_k86s7_hc_cdj7801.cfg (source) assets/cfg_k86s7_hc-cdj7801.cfg (destination) (renaming files)

2. Git add assets/

3. Git commit assets/--amend

4. Git push Origin Head:refs/for/master

Update the submission, the possible use scenarios are: Modify the file again, add changes ... Add parameter to "Git commit ...":-amend to implement commit modification.

3. View all the branches of the current directory, including: local branch and Remote branch.

Git branch-a

The above instruction can not only obtain the local branch situation, but also get the remote branch situation.

Git branch-vv

The above instruction can obtain the remote branch that the current head points to.

4. Create a branch from the remote branch and view the correspondence between all branches and the remote branch.

[Email protected]/f/sptsrcgit/Factorytest (develop) $ git branch-a*Develop remotes/origin/head-origin/Master Remotes/origin/Develop remotes/origin/mx1/teyes/T7 Remotes/origin/Test[email protected]/f/sptsrcgit/Factorytest (Develop) $ git checkout-B mx1/teyes/t7 origin/mx1/teyes/T7branch MX1/teyes/t7 set up to track remote branch mx1/teyes/T7 from Origin. Switched to aNewBranch ' MX1/TEYES/T7 '[email protected]/f/sptsrcgit/factorytest (mx1/teyes/T7) $ git statuson branch mx1/teyes/T7your Branch is up-to-date with ' origin/mx1/teyes/t7 '. Nothing to commit, working directory clean

Using "Git checkout-b ...", parameter-B is the creation of a branch, and the above instruction achieves the purpose of creating and switching branches.

5. Save the changes to the current branch before switching branches, and revert the changes when returning.

[Email protected]/f/sptsrcgit/Factorytest (Develop) $ git stashsaved working directory and index state WIP on develop:9c721b0 resolves a crash that could be caused when no SN or IMEI number is resolved Solve the GPS test item by clicking the Home button, resulting in other test item results error problem; increased Adas test item head is now at 9c721b0 resolves a crash issue that may arise when no SN or IMEI number is resolved; Click the Home button in the GPS test Causes other test item results to be wrong; add adas test item [email protected]/f/sptsrcgit/Factorytest (Develop) $ git Stash popon Branch Developyour Branch is up-to-date with ' Origin/develop '. Changes not staged forCommit: ( use"Git add <file> ..."To update what'll be committed) ( use"Git checkout--<file> ..."To discard changes in working directory) modified:. classpath modified:local.properties MoD IFIED:SRC/com/spt/view/Sptactivity.javano changes added to commit ( use"Git add" and/or "Git commit-a") Dropped Refs/[email protected]{0} (44CFAA42768EF50D6B82DB4C2E8D2DEE508B00B4)

The above instructions are executed: Save the changes, restore the role of the modification.

6. In the local file system, set up the remote repository and clone the repository, and submit the update in the local repository.

Step 1: Create a local branch

[Email protected] mingw64/d/gitdemo$ cd remotegit/[email protected]-pc mingw64/d/gitdemo/--  bareinitialized empty Git repository in D:/gitdemo/remotegit

Step 2: Create a clone of the above warehouse (remote warehouse) locally and use it as a local warehouse

[Email protected] mingw64/d/gitdemo/demo$ git clone. /remotegit/' remotegit ' ...warning:you appear to has cloned an empty repository.done.[ Email protected]-pc mingw64/d/gitdemo/demo$ lsremotegit/

Step 3: In the local warehouse above, create the A.txt file and submit it to the remote branch

[Email protected] mingw64/d/gitdemo/demo/Remotegit (Master) $ echo111 >>A.txt[email protected]-PC mingw64/d/gitdemo/demo/Remotegit (Master) $ cat A.txt111[email protected]-PC mingw64/d/gitdemo/demo/Remotegit (Master) $ git statuson Branch Masteryour branch is up-to-date with ' Origin/master '. Changes not staged forCommit: ( use"Git add <file> ..."To update what'll be committed) ( use"Git checkout--<file> ..."To discard changes in working directory) Modified:a.txtno changes added to commit ( use"Git add" and/or "Git commit-a") [email protected]-PC mingw64/d/gitdemo/demo/Remotegit (Master) $ git Add. WARNING:LF would be replaced by CRLF in A.txt.the file would have their original line ending s in your working directory. [Email protected]-PC mingw64/d/gitdemo/demo/Remotegit (Master) $ lsa.txt[email protected]-PC mingw64/d/gitdemo/demo/Remotegit (Master) $ cat A.txt111[email protected]-PC mingw64/d/gitdemo/demo/Remotegit (Master) $ lsa.txt[email protected]-PC mingw64/d/gitdemo/demo/Remotegit (Master) $ git statuson Branch Masteryour branch is up-to-date with ' Origin/master '. Changes to IS committed: ( use"Git reset HEAD <file> ..."To Unstage) Modified:a.txt[email protected]-PC mingw64/d/gitdemo/demo/Remotegit (Master) $ git commit-M "Add 111 to A.txt"[Master 07E3FC3] Add111To a.txt1 file changed, 1 insertion (+) [email protected]-PC mingw64/d/gitdemo/demo/Remotegit (Master) $ Git push Origin headcounting objects:3, done. Writing objects:100% (3/3), Bytes | 0 bytes/s, done. Total3 (Delta 0), reused 0 (Delta 0) to D:/gitdemo/demo/. /remotegit/bdaf647. 07E3FC3 HEADMaster

The above uses GIT push Origin HEAD, where: head points to the local current branch master (if the current branch is develop, the head represents the develop branch) ; means to push the local work branch to the remote work Branch (master or other branch).

Step 4: In the local repository, create a new Develop_test branch based on the remote Master branch and commit the update to the remote master branch

[Email protected] mingw64/d/gitdemo/demo/Remotegit (Master) $ git checkout-B develop_test origin/Masterbranch Develop_test set up to track remote branch master from Origin. Switched to aNewBranch ' Develop_test '[email protected]-PC mingw64/d/gitdemo/demo/Remotegit (develop_test) $ lsa.txt[email protected]-PC mingw64/d/gitdemo/demo/Remotegit (develop_test) $ cat a.txt111[email protected]-PC mingw64/d/gitdemo/demo/Remotegit (develop_test) $ cat222 >>A.txtcat:222: No Such file or Directory[email protected]-PC mingw64/d/gitdemo/demo/Remotegit (develop_test) $ echo222 >>A.txt[email protected]-PC mingw64/d/gitdemo/demo/Remotegit (develop_test) $ git statuson Branch Develop_testyour branch is up-to-date with ' Origin/master '. Changes not staged forCommit: ( use"Git add <file> ..."To update what'll be committed) ( use"Git checkout--<file> ..."To discard changes in working directory) Modified:a.txtno changes added to commit ( use"Git add" and/or "Git commit-a") [email protected]-PC mingw64/d/gitdemo/demo/Remotegit (develop_test) $ git Add. WARNING:LF would be is replaced by CRLF in A.txt.the file would have their original line Endings in your working directory. [Email protected]-PC mingw64/d/gitdemo/demo/Remotegit (develop_test) $ git commit-M "Add 222 to A.txt in Develop_test branch"[develop_test c522e2e] Add222To a.txt in Develop_test branch1 file changed, 1 insertion (+) [email protected]-PC mingw64/d/gitdemo/demo/Remotegit (develop_test) $ git branch-VV* Develop_test c522e2e [origin/master:ahead 1] Add 222To a.txt in develop_test branc H master 07E3FC3 [Origin/master] Add 111To A.txt[email protected]-PC mingw64/d/gitdemo/demo/Remotegit (develop_test) $ Git push Origin head:mastercounting objects:3, done. Writing objects:100% (3/3), 280 bytes | 0 bytes/s, done. Total3 (Delta 0), reused 0 (Delta 0) to D:/gitdemo/demo/. /remotegit/07E3FC3. C522E2E HEADMaster

Above use: Git push Origin head:master represents an update of the current work branch develop to the remote Master branch.

Step 5: Verify that the remote master has changed

[Email protected] mingw64/d/gitdemo/demo/' master' Origin/master ' by 1 commits, and can be fast-forwarded.  " Git pull "to update your local branch) [email protected]-pc mingw64/d/gitdemo/demo/remotegit (master) $ git fe Tch[email protected]-pc mingw64/d/gitdemo/demo/remotegit (master) $ git pullupdating 07e3fc3: C522e2efast-| 1 + 1 file changed, 1 insertion (+) [email protected]-pc mingw64/d/gitdemo/demo/remotegit (Master) $ cat a.txt< /c9>111222

The following is the. git directory saved in the local repository:

[Email protected] mingw64/d/gitdemo/localgit/-5drwxr-xr-x 1 James 197121  120 08:41./drwxr- Xr-x 1 James 197121  120 08:37. /drwxr-xr-x 1 James 197121  120 08:41. git/-rw-r--r--1 James 197121 220 08:41 A.txt

Or use a different way to verify:

[Email protected] mingw64/d/gitdemo$ CD Remotegit/[email protected]-PC mingw64/d/gitdemo/Remotegit (bare:master) $ git logcommit c522e2e50b79aac1be118b48ca7629f38356b296author:zhangefeng-james <[email protected]>Date:sat Nov19 23:36:22 2016 +0800Add222To a.txt in Develop_test branchcommit 07e3fc35d829b9cd6ff311a6a525b97d1e501612author:zhangefeng-james <[email protected]>Date:sat Nov19 23:09:47 2016 +0800Add111To A.txtcommit Bdaf647cfa610d73733060ae46c4c1ee8e3857b0author:zhangefeng-james <[email protected]>Date:sat Nov19 23:05:20 2016 +0800Init Master

As shown above, the creation and submission of remote and local branches is implemented.

7. Delete server-side file contents and submit Delete changes

[Email protected]/f/sptsrcgit/Cardoc (Master) $ git RM application Development/Design documentation/Factory Test Design Documentation _ Zhang Feng _11.21. Docrm' Application development/design document/Factory Test design Document _ Zhang Feng _11.21.doc '[email protected]/f/sptsrcgit/Cardoc (Master) $ git statuson Branch Masteryour branch is up-to-date with ' Origin/master '. Changes to IS committed: ( use"Git reset HEAD <file> ..."to unstage) deleted: Test design documentation _11.21st. Doc[email protected]/f/sptsrcgit/Cardoc (Master) $ git commit-M "Delete test design document, updated to 24th file"[Master 659232c] Delete test design documentation, updated to 24th file1 file changed, 0 insertions (+), 0 deletions (-) Delete Mode100644 Test Design Documentation _11.21. Doc[email protected]/f/sptsrcgit/Cardoc (Master) $ Git push origin head:refs/ for/mastercounting objects:17, done. Delta compression using up to4threads.compressing objects:100% (4/4), done. Writing objects:100% (4/4), 503 bytes | 0 bytes/s, done. Total4 (Delta 2), reused 0 (Delta 0) remote:resolving Deltas:100% (2/2) remote:processing changes:New: 1, Refs:1, Doneremote:remote:New Changes:remote:http://gerrit.y/3244 Delete Test design documentation, updated to 24th fileremote:to ssh://[Email Protected]:29419/yunovo_packages/cardoc* [NewBranch] HEAD--refs/ for/master

Git instructions involved: git rm <file-name>.

Git uses instance analysis

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.