The purpose of writing this article is simply to have a place to collect the commands I often use. (Old, bad memory, good memories as bad pen)
The text screenshots and the introduction of the project address may not be consistent, because most of the address has been modified, the omission may not be modified, screenshots more trouble, will not be a screenshot: 1. Apply for Gitlab account, get the SSH address of the project
Apply for the company's git account, assuming Gitlab address: http://192.168.1.1:80
Project address for Java Script project: (login Gitlab to create the corresponding project, need permissions)
Git@192.168.1.1:qa/auto_test.git
Corresponding HTTP address:
Http://192.168.1.1/qa/Auto_Test.git
2. Prerequisites for using git command
2.1 Installation Tools Git-1.9.5-preview20150319.exe
Go online to download, after installation, select a directory, click on the right button visible: Git Bash
2.2 Generate SSH key, get through Git Bash and Gitlab (git warehouse service)
First build a local warehouse directory, for example: D:\05-git-test
Select the directory and right-click and click Git Bash
Execute command: ssh-keygen-t rsa-c 123456@qq.com
#将邮箱替换成自己的邮箱;
#命令执行完会提示公钥和私钥文件产生的路径;
For example: C:\Users\Administrator.USER-20141014FO\.ssh
Copy the contents of the file id_rsa.pub into Gitlab, in the key in the following figure:
Test to see if SSH is properly connected:
Execute command: SSH git@192.168.1.1:qa/auto_test.git
3. Submit Eclipse Engineering code to remote GIT project for the first time 3.1 clone the remote Git warehouse to the local warehouse (D:\05-git-test) First
In Git Bash, execute the command: Git clone git@192.168.1.1:qa/auto_test.git
Then go to the local warehouse directory, as shown below:
Ps:
1. You can click on the title bar of Git bash-edit-paste the above command;
Right click-Edit-Mark is the function of copying;
2. Execute commands in Git bash like Linux;
3.2 Copy all files under the Eclipse Engineering directory to be submitted to D:\05-git-test\Auto_Test (same directory as. git)
The following figure:
3.3 Submit local warehouse code to git warehouse
To execute a command:
Cdapi_test_tools
Gitstatus #查看本地代码变更情况
Gitadd. #将本地当前目录下的所有文件, adding to the buffer
Gitcommit–m the "A-push script" #将缓冲区中的文件, submitted to Git's local server
#-M comments when adding code submissions
Gitpush Origin Master #将git本地服务器的代码提交到远程仓库的master分支上
Go to the Gitlab and see if the code is submitted to the corresponding item:
4. Clone existing code from GIT remote repository, make changes and resubmit 4.1, like 3.1. Execute clone command:
Gitclone Git@192.168.1.1:tests/auto_test.git
#注意选择该命令执行的目录
After the command is executed, the Auto_test directory is generated in the current directory, and a. git file appears in the directory.
#该目录下是有代码的, so do not work like 3.2; 4.2 open Eclipse and import the project from a remote clone into Eclipse, as shown in the following illustration:
Note: 1. Import in the form of MAVEN project ...
4.3 in eclipse, after adding or modifying a Java file, commit the modifications to the GIT remote repository
In Git bash, execute the command:
CD Auto_test
Gitstatus #查看本地代码变更情况
Gitadd. #将本地当前目录下的所有文件, adding to the buffer
Gitcommit–m "Modify Java Script" #将缓冲区中的文件, submitted to git local server
#-M comments when adding code submissions
Gitpull Origin Master
#每次提交修改内容到git仓库前, pull the latest code in the remote repository first,
See if someone else's changes are in conflict with their own changes.
after you execute the command, go into Eclipse and view the corresponding project:
If there is a conflict, eclipse will complain, as shown in the following figure:
You must manually modify the conflicting code before submitting it again, as shown in figure:
After the conflicting code is modified, execute the code again:
Gitstatus #如有冲突, the result of this command will be prompted
Gitadd.
Gitcommit–m "Fix Bug"
Gitpull Origin Master #虽然冲突已解决, or you must pull the code again
Gitpush Origin Master #提交修改到git远程仓库中
Note: Git status check for conflicts, never skip git pull, direct git push, it's possible to overwrite someone else's code 4.4 in Eclipse, if you delete some files or directories, commit this modification to a git remote repository
In Git bash, execute the command:
CD Auto_test
Gitstatus #可以检查出本地删除了哪些文件
GITRM Logs/xiaokatest_
GITRM Src/main/java/com/xiaoka/test/base/utils/testenvs.java
......
Supplemental Note: If there are many files that need to be deleted, the action is as follows:
git add--all (or git rm-r–cached.)
The delete operation is prudent.
Gitcommit–m "Delete logs file and Testenvs.java"
Git pull Origin Master Gitpush Origin master #没有冲突, after pull is push modified to git remote repository
5.q&a 5.1 How to submit an empty directory to a git warehouse
In an empty directory, create a hidden file (filename customization)
Under the Gitbash:
CD Empty directory Name
Touch.gitkeep
Add: There is an empty directory in the project, when the code is submitted, the error may be:
ERROR:SRC Refspec Master does not the match any. The 5.2 Part directory does not want to be submitted to the GIT repository and how to ignore them when submitting.
in the root directory of the Java project, place a. gitignore file, adding the following configuration:
/.settings/
/logs/
/target/
/test-output/
/.classpath
/.project
Indicates that these directories/files are not submitted to the GIT repository;
Description
1) logs is the log4j print log for local execution of the use case, Test-output is the testng output log, and target is automatically generated locally when compiling and executing.
2)/.settings/,/.classpath,/.project with the project in the local compilation environment, it is not submitted to git warehouse;
If a project that is moved from a git warehouse needs to be compiled:
Method: Clean the current project, will automatically compile the Java file, generate the files in the target directory;