catalogue
Git code pull push and conflict resolution
View local code change and code fallback version operations
SSH keys configuration
The corresponding project is created on gitlab. After entering the project details, a git address will be generated to clone or pull the code of the remote warehouse to the local warehouse. After the local warehouse changes the code, it will be pushed to the remote warehouse. The recommended ssh configuration is frequently used. The HTTP method requires entering the gitlab account and password every time.
First, confirm whether SSH has been used. When SSH is not used for too long, or the corresponding device terminal is replaced, and the corresponding Git operation is used again, an error "permission denied (public key)" will be reported. Follow the following two steps:
1. Check whether there is an ssh key on the computer
# Check whether the ssh key has been generated $ ls ~/.ssh/ # Check the public key and copy the corresponding public key to ssh key in Gitlab settings $ cat ~/.ssh/id_rsa.pub
2. When there is no ssh key, create the ssh key
# The command generates the key of the corresponding account of Gitlab $ ssh-keygen -t rsa -C 'gitlab Account name' # Check the public key and copy the corresponding public key to ssh key in Gitlab settings $ cat ~/.ssh/id_rsa.pub
Git branch
Common branches:
- master # main branch, with and only one
- The release version will be merged into the online version after the release version is branched to the online version
- The development branch of developep is usually a test deployment environment or a packaged branch. After each person develops on his own branch, he will merge with the development branch
- Feature # is usually a function branch or a personal branch. The usage of each company is different. There are usually many feature branches, which are usually deleted after the merge is completed
Create your own branch locally for pulling and pushing code on Gitlab:
To create your own local branch for the first time, you need to join the relevant accounts of gitlab:
# Join mailbox $ git config --global user.email "xx@xx.com" # Join user name $ git config --global user.name "xxx"
The operation commands for creating a local branch are as follows:
# View current branch $ git branch * master # Create and switch branches -- copy the code from the master branch to the new branch hd, and switch the branch to the test branch $ git checkout -b test Switched to a new branch 'test' # View the current branch on the test branch $ git branch * test master
Git code pull push and conflict resolution
After the software code is modified successfully, the code is pulled and pushed to the merge operation on Gitlab. Before pushing the code, you must note that the code is the path of the whole project file code, not the path of a file in the project.
# View remote branches $ git branch -a * test master remotes/origin/HEAD -> origin/master remotes/origin/develop remotes/origin/master # Submit change points $ git add . $ git commit -m 'xx change' # Pull and merge the remote code master branch and check whether there is conflict locally $ git pull --rebase origin master # Merge code from an unrelated remote develop ment branch to a local branch $ git pull --allow-unrelated-histories origin develop # Conflict resolution: from Gitlab Right click when there is a conflict in the pull-up code GIT=>Right click to select( Resolve Conflicts....)==>click merge Key to resolve the conflict # Submit change points after resolving conflicts $ git add . $ git rebase --continue # Add local change code and submit change point $ git add . $ git commit -am 'modify xx' # Forcibly push the command to Gitlab -- forcibly push after the user fails to push the remote branch $ git push origin test -f # Push local branch to remote branch $ git push origin test # Request merging on Gitlab and branch to master Enter into Gitlab On the official website of--Merge request--new merge request--To select the branch to merge, select the branch to merge( test),What branch do you want to merge into( master)upper--click COMPARE BRANCHES AND CONTINUE that will do # After you have the permission of maintainer or owner on Gitlab, you can choose. Click the "merge" button to the master branch, and click the merge button to merge the branch to the master # Push the local branch test to the remote develop ment branch -- no merging $ git push origin test:develop ### Otherwise, the error message is as follows: error: SRC refspec develop doors not match any error: failed to push some refs # Use the remote master branch locally and push the code to the remote branch -- no merging $ git push -u origin master
View local code change and code fallback version operations
# Check whether git software is installed $ git usage: git [--version] [--help] [-C <path>] [-c <name>=<value>] [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path] [-p | --paginate | --no-pager] [--no-replace-objects] [--bare] [--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>] <command> [<args>] # See how the file has been modified $ git diff # View merged code snippets $ git log # Fallback the workspace and cache to the specified log $ git reset --hard 03efbf2e4b652e9c4b4590935ddaf09d6beb89a0 HEAD is now at 03efbf2 update model