git software routine application method record

(1). Local warehouse

  1. Create a non-Chinese directory managed by git

  2. Execute the command git init in this directory

  3. Execute the command in the local repository directory:

git config --global user.name "your username"

git config --global user.email "your mailbox"

  1. 安装ssh-keygen
    sudo apt-get install openssh-client ssh-keygen

  2. Generate the ssh key, copy it to the pasteboard, and execute the command:
    ssh-keygen -t rsa -C "your mailbox"
    #Paste command
    clip <~/.ssh/id_rsa.pub

  3. Register an account, https://github.com/ or enterprise gitlab

  4. Setting --> Setting-SSH, create a new SSH keys and paste id_rsa.pub into the keys

  5. The test is successful, execute the command:
    ssh -T [email protected]

(2). Associate remote warehouse

  1. Local warehouse associated with remote warehouse
    Go to github and find the warehouse SSH address starting with [email protected]: in the warehouse Clone or download drop-down list and copy it (because HTTPS is slow, generally use SSH address)
    git remote add origin the address you copied
    git remote add origin xxxxx

  2. Synchronize remote warehouse

Note: If there are files in the remote warehouse, first pull the contents of the remote warehouse
git pull origin master
and then merge the local code, push the code to the remote warehouse
git push -u origin master
Note: When the remote warehouse is empty, you can force the synchronization of the remote warehouse
git push -u -f origin master

3. Re-associate the remote warehouse:
git remote rm orgin //Delete the original remote warehouse address
git remote add group //The newly associated remote warehouse address
git pull group master
git push -u group master

  1. The method of
    submodule association git submodule init # Initialize the local .gitmodules file
    git submodule add <submodule_url> # Add the sub-project URL
    git submodule update # Synchronize the remote submodule source code

Methods of uploading local submodules eg:

robot@ubuntu:~/routeMonitor/monitor_src/third_party/serial$ git reflog
cbcca7c HEAD@{
    
    0}: clone: from https://github.com/wjwwood/serial.git
robot@ubuntu:~/routeMonitor/monitor_src/third_party/serial$ cd ../../
robot@ubuntu:~/routeMonitor/monitor_src$ git submodule add https://github.com/wjwwood/serial.git
Cloning into 'serial'...
remote: Enumerating objects: 2659, done.
remote: Total 2659 (delta 0), reused 0 (delta 0), pack-reused 2659
Receiving objects: 100% (2659/2659), 1.55 MiB | 354.00 KiB/s, done.
Resolving deltas: 100% (1240/1240), done.
Checking connectivity... done.

robot@ubuntu:~/routeMonitor/monitor_src$ git status
On branch master
Your branch is up-to-date with 'DevGroup/master'.
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)
	new file:   .gitmodules
	new file:   serial
  1. Delete the test folder as a case
    git rm -r --cached test //--cached will not delete the local test
    git commit -m'delete test dir'
    git push -u origin master

  2. Add file
    git add…
    eg:git add ConfigVersionNumber.h

  3. Confirm the merged content
    git commit -am "he c_with_ui.cpp file macro definition"
    push to the server, submit the application
    git push origin master

  4. Submit the merge application
    web interface and log in to the github account, you can submit the current code application to merge into the R&D group.

(3). Resolve merge conflicts

Basic tools:
sudo apt install kdiff3

  1. View version merge conflict content
    git mergetool

  2. Resolve merge conflicts
    git difftool

  3. Confirm the merge
    git commit -am "Merge completed"

  4. Submit local code
    git push origin master

(4). Create branch and merge branch

  1. Create branch
    git branch dev

  2. After the code of the dev branch reaches the online standard, it must be merged into the master branch
    git checkout dev
    git pull
    git checkout master
    git merge dev
    git push -u origin master

  3. When the master code changes, you need to update the code on the development branch (dev)
    git checkout master
    git pull
    git checkout dev
    git merge master
    git push -u origin dev

(5). Roll back a specific version

1). 在git工作路径,git reflog 查看本地,git log查看远程。
2). 查看指定历史版本 tree 的 SHA; 
3). 指定远程 commit 值
			$ git checkout 4dc7ce33fab01e8ff1858968062c6d57bf2e7571
			
			/*
			Note: checking out '4dc7ce33fab01e8ff1858968062c6d57bf2e7571'.
			You are in 'detached HEAD' state. You can look around, make experimental
			changes and commit them, and you can discard any commits you make in this
			state without impacting any branches by performing another checkout.			
			
			If you want to create a new branch to retain commits you create, you may
			do so (now or later) by using -b with the checkout command again. Example:
			git checkout -b <new-branch-name>
			*/	
			
			$ git branch
			* (HEAD detached at 4dc7ce3)
			  brain_8.10
			  dev
			  master
4). 把此分支check到 此分支上
		git checkout -b brain_8_9 

5). //把此分支推到服务器上,服务器上就出现版本的分支代码 
		git push origin brain_8_9 

6).切换至另一文件夹内,下载分支代码。
$ git clone -b brain_8_9 ssh://git@git.keyi.lan:10022/lijiabo/cellrobot2_app.git
				Cloning into 'cellrobot2_brain_app'...
				remote: Enumerating objects: 1913, done.
				remote: Counting objects: 100% (1913/1913), done.
				remote: Compressing objects: 100% (1456/1456), done.
				remote: Total 1913 (delta 1460), reused 578 (delta 451)
				Receiving objects: 100% (1913/1913), 556.19 KiB | 7.32 MiB/s, done.
				Resolving deltas: 100% (1460/1460), done.
$ ls
	cellrobot2_app
$ git branch
   * dev
	master

Git instruction document
https://git-scm.com/book/zh/v2

Guess you like

Origin blog.csdn.net/weixin_38387929/article/details/112789914