now start with a story:
When it comes to versioning, there's always a picture in my head. College graduation is the scene of graduation thesis, your computer graduation thesis must have appeared this scene!
Graduation Thesis _ First draft. DOC Graduation Thesis _ Revise 1.doc graduation Thesis _ Revise 2.doc graduation Thesis _ Revise 3.doc graduation Thesis _ Full version 1.doc Graduation Thesis _ Full version 2.doc Graduation Thesis _ Full version 3.doc Graduation Thesis _ Final Edition 1.doc Graduation thesis _ Final version of the 2.doc graduation thesis _ Death is not revised. Doc ...
The above is the most primitive way to version control, but this approach has significant drawbacks:
- Multiple files, keep all versions when you need to save one file for each version ...
- Collaborative operation, multi-person operation, the need to package files sent to send ...
- Easy to lose, to be deleted means to lose forever ... (You can choose a network disk)
In order to solve the above version control problems, a batch of version control tools emerged: VSS, CVS, SVN, git, etc., Git is the absolute supremacy.
1. First go to download git
Git is a software that helps users implement version control
Git is an open source distributed version control system for agile and efficient processing of any or small or large project.
Git is an open source version control software developed by Linus Torvalds to help manage the development of the Linux kernel.
Unlike the commonly used version control tool, CVS, Subversion, Git uses a distributed repository approach without the need for server-side software support.
Little a entrepreneurial note:
The first stage: the Day in Shahe
Small A is a young and promising programmer, from childhood determined to do something big, a late-night small A in the online search * * Teacher starring Learning Video, spent 1 hours to find the resources, small a think and their own as the same young people spend a lot of time to find like the teacher's work, feel that their opportunities to do great things, Resolutely choose entrepreneurship, create a XX platform
Command:
Git init #初始化
After initialization, the. Git folder is automatically created in the current directory, which is the most important folder in Git, because git-related files and versions will be saved in that folder, and with it, mom won't have to worry about my many files to remember.
version, the git command allows you to save all versions in a. git file, with two commands to create a version:
macbook-pro-4:p ondo wupeiqi$ git status #对指定文件夹下的所有文件及子目录进行版本控制 view current git state on branch masterinitial Commituntra cked files: ( use"git add <file>, ... ."To includeinchWhat would be is committed). idea/APP01/db.sqlite3 manage.py Pondo/Readme Templates/Nothing added to commits but untracked files present ( use"git add"to track ) MacBook-pro-4:p ondo wupeiqi$ git Add. # Add all the files in the current directory to the repository MacBook-pro-4:p Ondo wupeiqi$ git commit-m'first time Commit'# Submit to the repository and fill in the release notes so that you can roll back later. [Master (Root-commit) Df47fe4] first time commit -Files changed,879Insertions (+) Create mode100644. idea/dictionaries/wupeiqi.xml Create mode100644. idea/encodings.xml Create mode100644. idea/inspectionprofiles/profiles_settings.xml ...
Note: When you execute the git commit command, you may be prompted for user and mailbox configuration, which is used to log the current version submitted by that user
- git config--local user.name ' geping '
- git config--local user.email ' [email protected] '
Summary of BASIC commands:
- Git init, initialized, indicates that the current folder is about to be versioned.
- git status to see the current state of git, such as those files that have been modified, those files that have not yet been submitted to the repository, and so on.
- Git add file name to add the specified file to the staging state of the repository.
- git commit-m ' submit information ' to submit the staging area's file to the repository's branch.
- git log, view commit record, i.e.: History version record
- Git reflog
- git reset--hard commit record (version number)
Workspace: The current development program is located in the directory called the workspace, that is, the work development is in the directory, the region's files will change state and the state is automatically detected by git, if the program files do anything (add, delete, change), the file status will be detected, you can use "Git Status command to view the.
repository : The workspace detects that a file has changed, which means that the program has been modified later than the previous version, and after the modification is completed, it can be submitted as the next version, that is, "git Add." Commits all files to staging area and then executes "git Commit-m ' Another version ' commits to the branch of the repository and can then use the ' git log ' command to view the version history.
macbook-pro-4:p ondo jesi$ git logcommit 0972f4bb43104baee15aeec2dd62bd0a307ec837Author:jesi<[email protected]>Date:fri One Ten: Wu: the .+0800Africa Zone Online commit 6c439d2fd0d943f36f3ee84e158ff86b052961d2Author:jesi<[email protected]>Date:fri One Ten: the: the .+0800Project first ported to git control version
MacBook-pro-4:p Ondo jesi$git reset--Hard 6c439d2fd0d943f36f3ee84e158ff86b052961d2HEAD isnow when the 6C439D2 project is first ported to the Git Control version # command finished, all the files in the workspace will become the non-developed Africa Zone feature before, it's so cool .
Rollback is finished, small a in the thought if one day want to return to the version of the feature of the African zone what to do? Come on, you can't just look at the records and roll back through "git log" and go back to what you need to do:
macbook-pro-4:p ondo jesi$ git reflog6c439d2 [email protected]{2}: Reset:moving to 6c439d2fd0d943f36f3ee84e158ff86b052961d20972f4b [Email protected]{3}: Commit: Africa zone on-line 6c439d2 [ Email protected]{4}: Commit (initial): project first ported to git control version MacBook-pro-4:p Ondo jesi$ git Reset-- is now at 0972F4B Africa Zone on-line
The second stage: development of the live broadcast function during the development process temporarily need to fix bugs or temporarily have new features to come
Way One:
Git stash [save to work] after fixing the bug ...
git stash pop [get back] git stash store all the modified contents of the current workspace to "somewhere" and restore the workspace to a state that has not been modified in the current version git stash list View all records stored in "Somewhere" git stash clear empty "somewhere" git stash pops to get the first record from "Somewhere" Back to the workspace (there might be a conflict) git Stash the Apply number, the specified number record from "Somewhere" Back to the workspace (there may be a conflict) git stash drop number, delete the specified number of records git Stash helps us temporarily store the code that has developed some features, continue to do other things, and then come back to continue with the development.
Special: When executing a git stash pop command, you may encounter a conflict, because the code that fixes the bug urgently and the code stored in "Somewhere" through stash will have a coincident part, so there will be a conflict when executing git stash pop, conflict resolution conflict can occur.
Mode Two "Recommended use, companies are creating branches":
git branch dev create dev branch git branch bug create bug branch -D bug Remove Bug branch git checkout dev Jump to dev This branch bug fix completed. jump to master to merge the bug's code over the git merge bug
Branch Learning: Branch is called a branch, and by default there is only one branch named Master. The general development of the new function process is: the development of new features will be on the branch Dev, after the development is completed and then merged into the master branch.
The whole process is like this:
macbook-pro-4:p ondo wupeiqi$ git branch # Current in Master branch *Master MacBook-pro-4:p ondo wupeiqi$ git branch dev # Create dev branch to develop new features MacBook-pro-4:p ondo wupeiqi$ git checkout dev # switch to Dev branch switched to branch'Dev'MacBook-pro-4:p Ondo wupeiqi$ Vim app01/views.py # Develop new features to half, need urgent fix bug MacBook-pro-4:p ondo wupeiqi$ git Add. MacBook-pro-4:p Ondo wupeiqi$ git commit-m'new feature development Half'[Dev B3AC2CB] new feature development half1File changed,2Insertions (+) MacBook-pro-4:p Ondo wupeiqi$ git checkout master # Switch back to the master branch switched to branch'Master'MacBook-pro-4:p ondo wupeiqi$ git branch bug # Create bug branch MacBook-pro-4:p ondo wupeiqi$ git checkout bug # switch to Bug branch switched to branch'Bug'MacBook-pro-4:p Ondo wupeiqi$ Vim pondo/settings.py # fix bug MacBook-pro-4:p ondo wupeiqi$ git Add. # Submit a bug MacBook-pro-4:p Ondo wupeiqi$ git commit-m'Emergency Fix Bug' # submit Bug[bug f42f386] Emergency fix bug1File changed,1Insertion (+),1Deletion (-) MacBook-pro-4:p Ondo wupeiqi$ git checkout master # Toggle will masterswitched to branch'Master'MacBook-pro-4:p ondo wupeiqi$ git merge bug # merges the bug branch content into the master branch, indicating that the bug has been repaired and can go online Updating 0972f4b. F42f386fast-forward Pondo/settings.py |2+-1File changed,1Insertion (+),1Deletion (-) MacBook-pro-4:p ondo wupeiqi$ git checkout dev # switch to Dev Branch and continue developing new features switched to branch'Dev'MacBook-pro-4:p Ondo wupeiqi$ Vim app01/views.py # Continue to develop half of the other features MacBook-pro-4:p ondo wupeiqi$ git Add. # Submit new feature MacBook-pro-4:p Ondo wupeiqi$ git commit-m'Continue development Complete'# Submit function [Dev C0bfb27] continued development completed1File changed,1Insertion (+) MacBook-pro-4:p Ondo wupeiqi$ git checkout master # Switch back to the master branch switched to branch'Master'MacBook-pro-4:p ondo wupeiqi$ git merge dev # merges the Dev branch into the master branch merge made by the 'Recursive'strategy. APP01/views.py |3+++1File changed,3Insertions (+)
Here is a face question asked is: A temporary bug on the line, how to solve?
First create a branch of the bug,
The Code modification processing is done in the merge to master,
Finally, delete this bug branch,
Go back to Dev branch to continue development.
The third stage: in three Li Tun bought a floor, no longer confined to the home.
Web sites or platforms that require code hosting: GitHub
' Version Information '
Upload code git Remote add origin https://github.com/jesidream/pay.git give address an alias Origingit Push Origin master pushes local master branch content and version information to GitHub input username password upload complete!
git push origin dev
将本地dev分支内容以及版本信息推送到GitHub
in the company ,
The first time a new computer is used, it needs to get the code out of GitHub and continue to develop, and go home from work when it's finished.
Developed the 1/' first day to develop 1/3 member features '
Home
when you get home Git pull Origin Dev then it's the member who developed the 1/' Member feature development complete 'git push Origin dev
The next day went to the company:
Git pull Origin Dev it was written last night.
If git log
then the member function development completed the first day of development 1/3 of these two versions have.
Command:
Git Remore Add origin https://xxxxxgit push Origin dev pushes up code git clone httos:// Github.com/xxxxxgit pull origin dev down code git fetch Origin Devgit merge Origin/Devgit pulls Origin Masterg It fetch origin master Git merge Origin/master change: Git rebase origin/dev
Interview question: What is git rebase?
Keep a clean commit record. [Cleanliness of submitted records]
The use of Git and GitHub