1. initialize a git repository and use the GIT init command.
2. Add the file to the GIT repository in two steps:
Step 1: run the GIT add command. Note that you can use it multiple times to add multiple files;
Step 2: Run git commit.
3. view the status of the workspace and use the git status Command.
If git status tells you that a file has been modified, you can use git diff to view the modification content.
4. Version Switching
Git allows us to switch between version history and use the GIT reset -- hard commit_id command.
Before switching, you can use git log to view the submission history to determine the version to be rolled back.
To return to a future version, use git reflog to view command history
5. Run the GIT add command to put all the modifications to be submitted in the stage. Then, execute git commit to submit all the modifications in the temporary storage area to the branch at a time.
6. Undo the modification.
1: When you change the content of a file in the workspace and want to discard the modification, run git checkout -- file.
2: When you not only disrupt the content of a file in the workspace, but also add the file to the temporary storage area, you want to discard the modification in two steps. The first step is to use the command git reset head file, return to scenario 1. Step 2: perform operations based on scenario 1.
7. delete an object
Git RM is used to delete a file. If a file has been submitted to the version library, you never have to worry about accidental deletion. However, you can only restore the file to the latest version, and the last modified content after submission will be lost.
8. remote warehouse
Create an SSH key: $ ssh-keygen-t rsa-c "[email protected]"
Associate remote Repository: git remote add origin [email protected]: andresjing/learngit. Git
Push all the content of the local database to the remote database:
Initial: $ git push-u origin master
Again: $ git push origin master
9. To clone a repository, you must first know the repository address and then use the GIT clone command to clone the repository.
$ Git clone [email protected]: andresjing/gitskills. Git
10. branch management commands:
View branch: git Branch
Create branch: git branch name
Switch branch: git checkout name
Create + switch branch: git checkout-B Name
Merge a branch to the current branch: git merge name
Delete branch: git branch-D name
11. Merge conflicts
When git cannot automatically merge branches, the conflict must be resolved first. After resolving the conflict, submit it again and merge it.
Run the GIT log-graph command to view the branch merge graph.
-- No-FF parameter, disable "Fast Forward": git merge -- no-FF-M "merge with no-FF" Dev
12. Save the site
Store the current job site and wait until it recovers. Continue working: git stash
View job site: git stash list
Recovery site:
First, use git stash apply [email protected] {0} to restore the file. After the file is restored, the stash content is not deleted and must be deleted by git stash drop [email protected] {0;
Another method is to use git stash pop to restore and delete the stash content;
13. To discard a branch that has not been merged, use git branch-D name to forcibly delete it.
14. working modes of multi-person collaboration:
First, you can try to use git to push origin branch-name to push your own changes;
If the push fails, you need to use git pull to try to merge the local updates because of the remote distribution ratio;
If a merge conflict exists, the conflict is resolved and submitted locally;
If there is no conflict or the conflict is resolved, you can use git push origin branch-name to push it!
If git pull prompts "no tracking information", the link between the local branch and the remote branch is not created. Run git Branch -- Set-upstream branch-name origin/branch-name.
15. Labels
The GIT tag name command is used to create a new tag. The default value is head. You can also specify a commit ID;
Command git tag to view tags. (tags are not listed in chronological order, but sorted alphabetically .)
Command git show tagname to view the description text;
Delete tags: $ git tag-D tagname;
Push a tag to a remote location: git push origin tagname;
One-time push all local tags that have not been pushed to the remote device: git push Origin -- tags;
The tag has been pushed to the remote device. to delete the remote tag, delete it from the local device: $ git tag-D v0.9; then delete it from the remote device: git push origin: refs/tags/v0.9;
16. GitHub
On GitHub, any fork open-source repository can be used;
Then, clone: git clone [email protected]: andresjing/Bootstrap. Git under your account;
You can push the pull request to the official repository to contribute code;
17. Create a. gitignore file under the root directory of the GIT workspace. Fill in the file name to be ignored, and git will automatically ignore these files.
18. Configure quick commands: git config -- Global alias. shortname ordername
19. Build a git Server
Step 1: Install git: $ sudo apt-Get install git
Step 2: Create a git user to run the GIT service: $ sudo adduser git
Step 3: Create a certificate Logon: Collect the public keys of all users who need to log on, that is, their own id_rsa.pub file, and import all the public keys to/home/git /. one line in the ssh/authorized_keys file.
Step 4: Initialize the GIT Repository: first select a directory as the GIT repository, which is assumed to be/srv/sample. git: Enter the command $ sudo git init -- bare sample in the/srv directory. git
Git creates a bare repository without a work zone. Because the GIT repository on the server is purely for sharing, users are not allowed to directly log on to the server to change the work zone, and the GIT repository on the server usually uses. git end. Then, change the owner to git: $ sudo chown-r git: git sample. Git.
Step 5: Disable shell Logon: For security reasons, the GIT user created in step 2 is not allowed to log on to the shell, which can be completed by editing the/etc/passwd file. Find a line similar to the following: git: X: 1001: 1001:,:/home/git:/bin/bash
Changed to: git: X: 1001: 1001:,:/home/git:/usr/bin/Git-shell.
In this way, git users can normally use git through SSH, but cannot log on to the shell, because the git-shell that we specify for git users will automatically exit upon every login.
Step 6: clone a remote Repository:
Now, you can clone the remote repository using the GIT clone command and run: $ git clone [email protected]:/srv/sample. Git on your computer.
Summary of Common commands
Address: http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000
Git Study Notes