Git command Summary (basic), git command summary basic

Source: Internet
Author: User

Git command Summary (basic), git command summary basic

I have been using Git for a while. As more projects become available, the number of function branches also increases. From simple basic commands to whatever I want, I need to keep trying to summarize it myself, the following is a summary of my Git usage.

This chapter describes the Git code submission process and the use of Git basic commands.

1. Git version branch management

The following is a basic branch management demonstration. The project management operations of each company are different, and the branch management also has its own characteristics.

1) dev branch for daily development

2) When a new version needs to be released, merge the dev code into the release branch for integration testing and wait for the release.

3) The release branch enters the bug fixing stage.

4) if a bug is found in the release branch, modify it in the release branch and use git cherry-pick to merge the bug fixing commit to the release branch.

(Different from merge, cherry-pick uses commit as the unit rather than the entire branch)

After that, all code changes (except the version number) on the release branch should have been merged to the dev branch.

5) release the release branch to the online environment after testing.

6) add tags and merge them to the master branch.

7) if a bug occurs online, hot fix on the master

8) after a hot fix occurs and the fix occurs, you need to merge the code of the hot fix into the dev and release branches to make the Code consistent.

Ii. Git basic command Summary1. view the local file status

Git status -- view the file modification status of the local, local repository, and cache (stash ).

-Red indicates file modification in the local workspace.

-Blue indicates the files submitted to the local repository (git add .)

2. Switch version/overwrite the current modified File

Git branch-view the current version

Git branch-a View All Versions

Git checkout XXX (version name) -- switch to the XXX version in the remote database

Git checkout filepath-overwrite the currently modified File

Git checkout.-overwrite all current modified files

3. obtain the latest code from the remote database

Git remote-view the remote database name

Git remote-v

Git remote show XXX (remote database name)

Git fetch-pull the latest code from the remote end

Git pull XXX (remote database name) XXX (branch name)-merge the pulled latest code with the current Workspace

Git rebase-merge the code pulled back remotely with the local code

4. cache local code

When you want to switch to another version, you want to save the file modified in the current version:

Git stash -- put locally modified files that do not need to be submitted into the cache

Git checkout XXX (Version)-switch the library version

Switch back to the original database and take the file out of the stash cache.

Git stash pop-pull from Cache

5. Submit the remote database

Git add.

Git commit-m''

Git remote view remote Association name

Git push remote name local master

6. handle conflicts

Git fetch pulls the latest project

Git pull XXX (remote database name) XXX (branch name)-merge the pulled latest code with the current Workspace

After a conflict occurs, go to the workspace and modify it. >>> new code === old Code <, retain the final code, delete the prompt, and submit again.

7. Submit the submitted content to other branches (for example, modifying the bug during release)

Git cherry-pick commitId

8. Recommended execution sequence

Git status to view the modification status

Git checkout filename abandons the modification of a file.

Git stash storage Modification

Git fetch pulls the latest project

Merge git rebase with local branch

Git stash pop pops up to store files. At this time, new files may conflict with your files and resolve the conflicts.

Git add filename add a modified File

Git add. Submit all vertices

Git reset HEAD filename: roll back the specified file and add "git reset HEAD ."

Git commit-m''

Git push local remote branch name, local branch name

For example, if my local branch is master, and the remote alias is origin, it is submitted as git push origin master.

9. Switch HEAD

Git reflog -- View HEAD records

Git reset -- hard HEAD ^ // switch to the previous HEAD

Git reset -- hard fad4462 // switch to a rollback HEAD

10. exclude local branch

Git branch-d <branch_name>

 

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.