Git and github, gitgithub
Git-version control, multi-person collaboration, distributed;
Github-open-source project, remote repository;
I have built a repository on github: https://github.com/abcd/2016ife;
Now I want to download it to my local computer;
Cd g:
Cd github/test
Git clone urlHere url fill the repository address; for example: https://github.com/abcd/2016ife.git
Cd 2016ife
The entry is as follows:
Git config -- global user. name "xxxxxxx"// Set the global user name. If you do not receive a prompt after you press enter, the setting is successful;
Git config-global user. email "xxxxx@163.com"// Set the mailbox
With these two records set, the two records will be stored in the version library when we submit the code, which can be viewed by others;
Git config -- global user. email// You can check the settings. After you press enter, the email address is printed;
Git config -- list// View all configurations
Master is the default name of the main branch. Creating a branch does not affect the stability of the master branch. When the branch is ready, it is merged to the master branch.
GitThree Zones:
Workspace, temporary storage area, version area (Library)
Workspace --> temporary storage zone --> Version Zone
Temporary Storage Area: Code submitted to the version area in the work area must go through the temporary storage area;
First, the changed code will be thrown into the temporary storage area, and then the temporary storage area will be thrown into the version area;
Temporary Storage zone: Used as a transition layer to avoid misoperation, protect the work zone, version zone, and branch processing;
Git status // View the status of the current workspace and temporary storage area
Prompt: nothing to commit ......
I copied the xinshijie folder to the local 2016ife folder, and then entered git status on the command line.
Indicates that the content of a folder has not been submitted to the temporary storage area and version area, and is currently in the work area;
Git addXinshijie/ // Add it to the temporary storage area,GitAddFile NameThe file name can be a specific file or a folder name;Git add.Add all to the temporary storage area;
We can see that the red is + 1 ~ 0-0 indicates that in the workspace, there are 1 new file (folder), 0 changes, and 0 deleted files;
The green area is the temporary storage area. In the end, the red area is invisible, indicating that the work area is clean;
Therefore, from the workspace to the temporary storage area, you can use the git add command to implement it;
Next, put the temporary zone file into the version Library:
Git commit // A notepad will pop up directly. We need to add a comment.Git commit-m "change demo1"In this way, the notepad will not be opened, but the notes will be added quickly;-M"Comment content";
Git commit-a-m"Quick notes"// You can directlyFrom work zone to version Zone;-Is shortAdd, TianAdd to temporary storage Zone;
Use againGit status;One version has been submitted;
Git log// View the submission history and press q to exit;
Git diff // Compare the differences between the workspace and the temporary storage area;
Git diff -- cached (Git diff -- staged)// Compare the differences between the temporary storage zone and the version library;
Git diff master// Compare the differences between the workspace and the version library;
Undo operation:
Git reset HEAD <file. name>// Withdraw from the temporary storage area to the workspace. <file. name> enter the file name.
Git checkout -- <file. name>// Undo from workspace back to version Area
Git commit -- amend// Undo the submit operation
Note:
The logic here is as follows: I now have two files in the workspace; I first added drag.js to the temporary storage area, and then handed it to the temporary partition area. Then I found that some demo1.html files were not submitted; in fact, my idea is to submit the two files at a time (the version involved). Solution: Add demo1.html to the temporary storage area first, and then use git commit-m "change3 drag. js and demo1.html "-- amend will undo the last commit and submit it together. In this way, the Undo is completed and the two files are submitted together.
Delete
Git rm <file. name> // Delete the content of the temporary storage area. If a file is deleted in our workspace, use this command to delete the temporary storage area;
Git rm-f <file. name>// When files exist in both the workspace and the temporary storage area,Force DeleteFiles corresponding to the temporary storage area and work area;
Git rm -- cached <file. name>// When files exist in both the workspace and the staging area, only files in the staging area are deleted, but workspace files are retained;
Restore
You can view the cmmit ID through git log.
Git checkout commit_ Id <file. name>// Restore the specified file
Git reset -- hard commit_id// Restore to a previous version
Head version pointer, pointer to control version
Git reset -- hard HEAD ^ // Return to the previous version
Git reflog// View all operation records of all branches (including commit and reset operations)
Use this methodGit reset -- hard commit_ IdIt can be restored to the previous version;
Next we will upload the local development to github;
First, we need to log on to the github client. First, we can check whether the github account has been logged on;
Git remote// View the remote repository name. The default value isOriginThis name
Git remote-v// View the address of the corresponding remote warehouse
Git pushOriginMaster//Git push the branch whose remote repository name is to be synchronized
In this way, we submit it to the remote warehouse;
When multiple users collaborate, add new collaborators;
In this way, a request is sent to the user to develop the project together;
Another person still usesGitClone urlTo obtain the local data. The subsequent operation commands are the same;
Collaborative Development
Pull and synchronize updates to avoid conflicts;
Collaborative resolution of conflicts;
Differences between git pull and git fetch:
Git fetch// Do not merge to the Branch. resolve the conflict first, and then manually merge
Git diff master origin/master// View the difference
Git merge origin/master// Manually merge
Git pull// Directly merged into the file, so it is not easy to see the difference;
Open-source project collaboration: fork first, and then pull request
How do I participate in open-source projects without permissions?
Fork completely mirrors a version and puts it in its own account...
After modification, pull request is sent to the author's side;
Delete Repository
Delete this repository in settings; Be careful not to delete it by mistake. If you delete it, you cannot find it.
Git command line
Http://www.cnblogs.com/sysu-blackbear/p/3463475.html