Git Learning Notes
@ (Python)
| git commands |
This is a common git command |
| Init |
Build a git repository |
| Add |
Add files to the warehouse |
| Commit |
Submit the file to the repository and submit the file in staging area to master |
| Status |
Master the status of the warehouse, see the changes, there is no submission |
| Diff |
=differents Change |
| Log |
View history, who, when, what changed |
| Reset |
Fallback |
| Reflog |
Keep a record of every command |
| Checkout–file |
Replace the contents of the workspace with the version in the repository;-B create the branch and switch to the branch |
| Rm |
Delete |
| Branch |
View current Branch-D Delete Branch |
| Merger |
Branch merge to current branch branch |
| Stash |
Storage work site |
| Stash List |
Job Site List |
| Tag |
Hit label |
远程库 |
|
| Clone |
Cloning Remote Libraries |
| Git remote-v |
View Remote Library Information-V details |
| Git push Origin Master |
Push a branch |
| Status |
|
| untracked |
has not been added |
| Changes not staged for commit: |
added, but the change has no add |
| No tracking information |
Links to local and remote branches are not created |
Add File Method
git add "files"//adding files to Staging Area
git commit-m "description"//submits all content in staging area to the current branch
Version fallback
In Git, the current version is represented by head, and the previous version is head^, which is written in 100 versions head~100
eg
Back to previous version
$ git reset–hard head^//or write commit ID
HEAD is now at ea34578 add distributed
Check the log again and find out that the last update is gone, so how do I update it back to this version, go up and find the previous version number
$ git reset–hard 3628164
HEAD is now at 3628164 append GPL
You can do that.
Git Reflog//will show all the historical operations
Git's version fallback is very fast because git has a head pointer to the current version inside, and when you roll back the version, git just points the head from the other version.
How Git Works
The workspace is the path in the real computer. Included in the repository, staging area and master
The workspace has a hidden directory. Git, this isn't a workspace, it's a git repository.
Git has a lot of stuff in its repository, the most important of which is the staging area called stage (or index), and the first branch master that git automatically creates for us, and a pointer to master called head.
How to remove files that you do not want to add
First add a large number of files at once:
Strong Textgit Add *.py
Then you use GIT status to view it with a hint:
Changes to be committed:
(use "Git reset HEAD ..." to Unstage)
New file:1.py
New file:2.py
New file:3.py
New file:4.py
To exclude one of the files, use:
git reset HEAD 1.py
At this point in the Git status, 1.py became untracked, the rest can be submitted.
Undo modify changes in the Undo workspace
Git checkout–file
If the modification is made to staging area, the workspace file reverts to the version in staging area, otherwise it reverts to the version in the repository.
Undo the changes submitted to staging area
git reset HEAD file
You can undo the staging area changes (Unstage) and put them back in the workspace.
Submit to Repository Fallback
If you do not commit to a remote library, you can see version fallback with reset fallback version
Remote Warehouse Link Remote Warehouse
1th step: Create SSH Key. In the user home directory, see if there is no. ssh directory, if there is, then look at this directory there are no Id_rsa and id_rsa.pub these two files, if already have, can jump directly to the next step. If not, open the shell (open git Bash under Windows) and create SSH Key:
$ ssh-keygen-t rsa-c "[Email protected]"
CD ~
Ls-a
Find the. SSH directory, there are Id_rsa and id_rsa.pub two files, these two are SSH key key pair, Id_rsa is the private key, can not be leaked out, Id_rsa.pub is the public key, can be assured to tell anyone.
1. Follow the prompts on Git to associate the local library to the remote
2. After association, use the command Git push-u Origin master to push all the contents of the master branch for the first time;
3. Thereafter, after each local submission, you can use the command GIT push origin master to push the latest changes whenever necessary;
Thereafter, after each local commit, whenever necessary, you can use the command GIT push origin master to push the latest changes;
Pull Remote Repository
git fetch [remote-name]
This command pulls all data that is not in your local repository to the remote repository. Once the operation is complete, you can access all the branches in the remote repository locally, merge one of the branches locally, or simply take out a branch to explore.
Cloning a remote repository
To clone a warehouse, you must first know the address of the warehouse and then clone it using the git clone command.
GIT supports multiple protocols, including HTTPS, but the native GIT protocol supported by SSH is the fastest.
Branch
Branching is a very important feature of git, and when you're developing new features (feature), it's a good idea to create a new branch.
When fixing a bug, we will fix it by creating a new bug branch, then merging and finally deleting;
Branching is also very useful when collaborating with multiple people, and the master version is a stable version, and if the 1.1 point is added, it will be used incorrectly, so the real development can be built into a dev branch, the time is ripe, and then the update is pushed to master.
Create a branch
Create a dev Branch
git checkout-b Dev
The git checkout command plus the-b parameter means create and switch, equivalent to the following two commands:
$ git Branch dev
$ git checkout dev//Switch branch
Switched to branch ' Dev '
View, merge, delete branches
git branch view current Branch
git merge Dev
Merges the current branch into the current branch
git merge–no-ff-m "merge with No-ff" Dev
Added a –no-of to merge the commit history from the branch to another branch
-d dev*** 删除分支
Resolve Merge conflicts
When two branches edit a file at the same time, there will be a conflict,<<<<<<<,=======,>>>>>>> the content of different branches to manually change the source file, and then submit.
Save work status
>git stash
After dealing with other things, find out the state of the work.
list //查看保存的工作状态
Resume working status
//恢复工作区>git stash drop //删除工作区
Equal to the two above
pop
You can stash multiple times, restore the time, first use Git stash list to view, and then restore the specified stash, with the command:
>$ git stash apply [email protected]{0}
Multi-person collaboration
Not too understanding, first occupy a hole.
Liaoche git tutorial-multi-person collaboration
Push local branch to remote library
Git push Origin Master
Not all local branches are pushed to the remote
Generally in multi-person collaboration, there are two branches, a master Master branch, Dev Development Branch, developers to synchronize development on the Development Branch progress
To view information for a remote library
>git remote // -v 详细信息
To create a remote branch locally
-b dev origin/dev
Label Management
When we publish a version, we usually start with a tag in the repository, so that it's the only version that determines the time of the tag. Any time in the future, the version of a tag is taken out of the historical version of that tag.
Make a label
git tag v1.0
You can also git tag view all tags
Submit a tag to history
Use git log --pretty=oneline --abbrev-commit the Commit ID you found in the history and then hit it.
git tag v0.9 6224937 //commit id
Tag information
git show <tagname>
Delete tag
git tag -d v0.1 //local
Remove remote Tag
Delete the local tag first
Remove from remote after leave
$ git push origin :refs/tags/v0.9
Push tag to remote
git push origin <tagname> //onlygit push origin --tags //push all local tag
Fork
How do I participate in an open source project? For example, the highly popular Bootstrap project, which is a very powerful CSS framework, you can access its Project home page https://github.com/twbs/bootstrap, point "Fork" in its own account under the cloning of a bootstrap warehouse , then, clone from your own account
git clone [email protected]:michaelliao/bootstrap.git
Be sure to clone the repository from your account, so you can push the changes. If the author of the bootstrap from the warehouse address [email protected]:twbs/bootstrap.git clone, because there is no permission, you will not be able to push the changes.
Configure aliases
Replace Dtatus with St
Liaoche-Configuring aliases
$ git config --global alias.st status
Common git directives