git basic operation

Leave it as a note for yourself later
Download git URL https://git-scm.com/downloads and click Next to install it. After the installation is complete, find Git->Git Bash in the start menu and a similar command line window will appear, successful

Some operations of the local warehouse:
global configuration:
git config –global user.name “Your Name”
git config –global user.email “[email protected]

1: Basic operation
1-Initialization: Create a new folder somewhere, which stores the files to be hosted git init Initialize the folder
2-Add: git add
3-Submit: git commit -m "Instruction information"
2: View the modification
4-git status View the current status
5-git diff View the difference between the latest submitted file and the current workspace file
3: Go back
6-git log --pretty=oneline View the commit log
7-git reflog View Commit_id
8-git reset –hard commit_id of each commit goes to a certain version
4: undo the modification
9-change the content of the workspace, but it has not been added to the staging area, use git checkout –
to abandon the modification of the workspace
10 - Changed the contents of the workspace and added it to the staging area at the same time, the first step: git reset HEAD undo the changes
in Using git checkout – undo the
changes in the workspace Back git reset –hard commit_id Go to a certain version
5: delete
12-git rm delete file If you
really want to delete the file, then submit the delete operation git commit -m "instruction information"
Deleted wrong, want to get it back, git checkout –
git checkout actually replaces the version in the workspace with the version in the repository, whether the workspace is modified or deleted

Local and remote operations:
1: Configure a remote repository
1-Register a github gitee account
2-Create an SSH Key Use the command ssh-keygen -t rsa -C "[email protected]"
to find the C:windows/user/.ssh directory id_rsa file, copy the content to the key text box in add ssh key under the account settings above github or gitee

2: Synchronize local and remote
1-Create a new warehouse on the remote, and enter basic information, select without readme.md file
2-Associate local and remote warehouses git remote add github(gitee) git@github(gitee).com :XX/XX.git
(The default name is origin, here it is changed to github, to associate the code cloud, it is written as gitee)
3-Push local to remote If it is the first git push -u github/gitee master
, use git push for later push github/gitee master
(Because the remote library is empty, when we pushed the master branch for the first time, we added the -u parameter, Git will not
only push the contents of the local master branch to the new remote master branch, but also push the local master branch to the new remote master branch. The master branch is associated with the
remote master branch, which simplifies commands for future pushes or pulls.)

3: Clone git from remote repository git clone git@github/gitee.com:XX/XX.git

4-If you have made changes on the remote side and want to synchronize the remote changes locally, git pull github/gitee master

5-If you want to use someone else's warehouse and submit your changes to others, fork first so that you have an additional warehouse under your account, make changes under your own warehouse, and push it to others

6-git remote -v Check that the local warehouse is associated with several remote warehouses. The name of the remote warehouse cannot be repeated.
7-Delete the locally associated remote warehouse git remote rm origin

8- Delete the contents of the remote warehouse but not locally

1.删除服务器文件,本地保留
git rm --cached useless.log

git commit -m "remove file from remote repository"
git push
no longer exists on github at this time

2.删除远程useless 文件夹,本地保留
一定要注意,删除文件夹要使用-r 参数
git rm --cached -r useless

git commit -m “remove directory from remote repository”
git push

From http://www.jb51.net/article/115029.htm

9- Ignore the file to be tracked
Open git bash and enter touch gitignore //Create an ignored
file Add the file you want to ignore and add the suffix to this file
Ignore folder: write the name of the folder directly +/

Branch management:
1: Basic operation
1-Create branch and switch branch git checkout -b
2-Create branch git branch
3-Switch branch git checkout
4-View branch git branch
5-Merge branch to current branch git merge
6-Delete branch git branch -d
When the operation on a branch is completed, it still needs to be merged after the add commit operation.
2: Merge conflict
occurs when changes are made in more than two branches and the changes are submitted, and conflicts will occur when merging , you need to manually change it, add commit
7-git log –graph –pretty=oneline –abbrev-commit on the main branch to view the branch merge status

Tag management:
1: Basic operations
1-git tag create a new tag, the default is HEAD, you can also specify commit_id
2-git tag is used to view all tags
3-tag a certain commit git tag version_id commit_id
4-git show version_id
5-git tag -a -m <description information> commit_id Label a commit and add descriptive text
6-delete the label git gat -d
2: Push the label to the remote
git push github/gitee version_id Push the specified commit_id to Remote
git push github/gitee –tags
Delete remote tags:
first delete git tag -d version_id locally
and then delete git push github/gitee :refs/tags/version_id remotely

Display Chinese garbled characters

git config –global core.quotepath false
git config –global i18n.commitencoding utf-8
git config –global i18n.logoutputencoding utf-8

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324645532&siteId=291194637