Git command summary


One, initialization


git config --global user.name "username"

Set git username

git config --global user.email "email"

Set git mailbox number

git init

Use the command git init to turn the current directory into a local warehouse managed by git

git add filename

Save the file to the temporary storage area

git commit -m "note"

Submit the file to the local warehouse


2. Common operations


git status

View the git status of the current library

git diff filename

Check the status of file changes

git log

View git operation log

git reset --hard HEAD~N

Roll back the git version to before the Nth version

git reflog

You can view the version number of each step of git (press Q to exit the view after viewing)

git reset --hard verNum

git to the specified version (according to the version number)

git checkout -- filename 

Discard the modification of the workspace. For example, there is no git add if the document is modified. The modification cannot be undone after add.

rm filename

Delete the file. After the deletion, git checkout-filename can undo the deletion and restore the file.


Third, the binding use of remote warehouses


ssh-keygen -t rsa -C "email"

Create SSH private key and public key

git remote add origion https://github.com/aaa/PC1.git

Use the public key of the PC from the previous step
to first enter the New SSH Key on the github personal account;
then create a new repository New repository, and after obtaining the http address of the repository, bind the
github library to the local PC . You need to enter the github account and account in git password.

git push -u origion master

Push the current branch master to the remote (github repository), add -u for the first time.

git push origion master

After the local and remote warehouse are bound, after modifying the local, use this instruction to synchronize to the remote warehouse.

git clone https://github.com/aaa/PC2.git

Clone from remote warehouse to local.


Four, branch operation


git branch

View all branches of git.

git checkout -b 分支名 

Create and switch to this branch. It is equivalent to the two instructions git branch bran1 and git checkout bran1.

git merge branch

Now we want to merge the content added on the branch branch to the current branch. You can use this command on the current branch (any branch).

git branch -d bran2

Delete a branch.

git pull

Get the latest content on the remote branch


Five, common process

Use Git to submit files to local and remote libraries:
1: Use git add filename to add files to the temporary storage area.
2: Use git commit -m "note" to submit changes, which is actually to submit all the contents of the staging area to the current master branch.
3: Use git push origion master: hand over the latest modification of the local master branch to the origin branch of GitHub. After this step is completed, you will truly have a distributed repository. (Centralized, distributed)

Branch management strategy:
Usually when we merge branches, Git generally uses the Fast forward mode. In this mode, after deleting the branch, the branch information will be lost. Now we use –no–ff to disable the Fast forward mode.
1: Create a dev branch. git checkout -b dev
2: Modify the content of README.md.
3: Add to the temporary storage area and work area. git add README.md \ git commit -m "change1"
4: Switch back to the branch of bran1. git checkout bran1
5: Merge the dev branch, use the command: git merge --no–ff -m "note" dev
6: After deleting the dev, we found that there are dev operations in the final log. git branch -d dev
7: View history. Git log
8: Branch strategy: The master branch should be very stable, and it is also used to release new versions. Under normal circumstances, work is not done on the master branch, but on the newly created branch. After doing it, it needs to be released. In other words, after the new branch code is stable, it can be merged into the master branch master.

Bug management strategy:
1: Hide the working status of the current branch git stash
2: Check whether the git status is clean. git status
3: Switch to the branch where the bug is located. gitcheckout branch
4: Create a new branch on the bug branch. git checkout -b branbug
5: Modify the bug code
6: Submit the modified file. git add filename\ git commit -m "fix bug xxx"
7: Switch to the branch where the bug is located. git checkout branch
8: merge the fix just now. git merge --no-off -m "note" branchbug
9: Delete the temporary branch that fixes the bug. git branch -d branchbug
10: Switch to the branch that is working in the first step. git checkout bran1
11: View the hidden work site. git stash list
12: There are two ways to restore:
a. git stash apply. After this restoration method, the stash content will not be deleted after restoration. You need to use git stash drop to delete it.
b. Another way is to use git stash pop to delete the stash content while restoring.

Multi-person cooperation: (local master branch) Corresponding (remote origin branch)
1: View remote information git remote
2: View detailed information about remote libraries git remote -v
3: Pull the latest origin to the current branch git pull
4: Modify content
5: Push your own changes to origion: git push origion branch-name


Six, note

If we change the local file without committing to a branch A, then under the branch A, cat filename will not see the local changes. And the commit under branch1, cat filename on branch2 can't be seen either.

Under normal circumstances, the master branch is the master branch, so it needs to be synchronized with the remote at all times; some fixed bug branches do not need to be pushed to the remote, as long as the master branch is merged locally to the master branch, and then the master branch master is pushed to the remote That's it.


Guess you like

Origin blog.csdn.net/LIU944602965/article/details/109119993