Migration or backup of libraries# #如我想把linux_ Datagrand.git the files in this library are migrated to Daguan.git as follows: (1) It is necessary to consider the existing branches when migrating, (2) to keep the previous submission records, (3) do not submit the local code directly to the Gitlab so that the previously submitted records and branches are not available. # #操作如下: Git clone ssh://[email protected]:19234/linux/linux_datagrand.gitcd linux_datagrandlsname.txt shiyan.txt# #查看当前的远程仓库: Git remote-vorigin ssh://[email protected]:19234/linux/linux_datagrand.git (fetch) Origin Ssh://[email protected]:19234/linux/linux_datagrand.git (push) # #添加daguan. Git, a remote repository git remotely add test Ssh://[email protected]:19234/linux/daguan.git Description: Add the remote warehouse format: Git remote add warehouse name [warehouse address]# #查看当前的远程仓库: Git remote- Vorigin ssh://[email protected]:19234/linux/linux_datagrand.git (Fetch) origin ssh://[email protected] : 19234/linux/linux_datagrand.git (push) test ssh://[email protected]:19234/linux/daguan.git (fetch) test ssh:// [Email protected]:19234/linux/daguan.git (push) # #把本地的分支push到远程仓库git Push-u Test Master This time there is an error, the content is as follows: Error: Failed to push some refs to ' Ssh://[email protected]:19234/linux/daguaN.git ' Hint:updates were rejected because the remote contains work which you dohint:not has locally. This was usually caused by another repository pushinghint:to the same ref. Want to first integrate the remote changeshint: (e.g., ' git pull ... ') before pushing Again.hint:See the ' Note AB Out Fast-forwards ' "Git push--help ' for details.# #解决方法: (1) because some branches of Gitlab are protected by default, only users with a master level can commit to the protection branch. and the master branch is the protection branch by default, and other users need to submit by merging issue requests. So we're going to turn this off. Master Branch Protection: Project: "Settings", "Repository", "Protected Branches (Expand)", "unprotect". (2) using the command: Git push-f test master so push the local branch to the Remote repository command: Git push-f test master# #这个时候, we've put Linux_ Datagrand.git the files in this library are migrated to the new library in Daguan.git.
Git pull and git pull--rebase
# #说明:
Git as a distributed version control system, all modifications are based on the local, in the team collaboration process, assume that you and your partner in the local each have their own new submissions, and your partner before you push the code to the remote branch, so you must first execute GIT pull to obtain the peer's submission, and then to Push your own commits to the remote branch. As with Git's default policy, if the commit line graph between the remote branch and the local branch is forked (that is, not fast-forwarded), Git performs a merge operation, resulting in a meaningless commit record, resulting in confusion over the submitted image.
# #解决:
In fact, when pulling operations, using the GIT pull--rebase option is a good way to solve the problem. With the--rebase parameter, Git will rebase the policy instead of the default merge policy if the submission line graph is forked. What are the benefits of using the REBASE strategy? It would be a good idea to borrow the figures from the man Git-merge.
Let's say that the commit line graph is this way before the pull is executed:
A---B---C remotes/origin/master / D---E---F---G master
If you are executing a git pull, the commit line graph will look like this:
A---B---C remotes/origin/master / D---E---F---G---H master
The result is an extra H this unnecessary commit record. If you are executing git pull--rebase, the commit line graph will look like this:
remotes/origin/master | D---E---A---B---C---F‘---G‘ master
F G Two commits are re-spliced after C by means of rebase, the excess fork is removed, and the purpose is achieved.
# #结论:
Most of the time, git pull--rebase is used to make the submission line graph look better, which facilitates code review.
However, if you are not very skilled with git, my suggestion is that git pull--rebase practice a few more times, because rebase is considered "dangerous behavior" in Git.
Also, it should be noted that using Git pull--rebase is more likely to lead to conflicts than direct pull, and if there are more conflicting expectations, it is recommended to pull directly.