How to use version control git

First of all, git is distributed, svn is centralized

git use

1.pwd: view the current file directory

2.cd: Jump to the home directory, (home directory: currently there is room for my account, I didn’t move it, see the picture)

3. Create a local account and mailbox

$ git config --global user.name "lxy"

$ git config --global user.email "[email protected]"

4.ls -a: show hidden files

5. Formally submit code, process: create file/modify file content--"View file status (red means not added to the cache)--"Add to cache--"View file status (green)--"Submit

1.touch c.php //创建文件
2.git status   //查看文件状态
3.git add c.php  //提交文件到缓存中
4.git commit -m "第一次提交"  //提交代码

6. Ignore settings of the version library, git add. You can add all modifications and add files to the cache, but some files may not be submitted, so we need to ignore some files

7. Delete from the repository, when we have submitted the file to the repository, but this file does not need to be submitted, it needs to be deleted

(1). Delete the local and version library together

git rm 2.php

(2) Do not delete locally. Delete from the repository

git rm --cached a.php

8. Modify the file name, change a to b

git mv a.php b.php

9. View log

git log

10. Modify the description of the last submission, (i, edit; esc,:wq to exit editing;)

git commit --amend

11. File operations in the temporary storage area

git restore --staged a.php   //在缓存区把a删除
git restore a.php            //将a上一次的修改删除

12. Branch commands

git branch                       //查看分支

git branch  xiaoyun              //创建xiaoyun分支

git checkout  xiaoyun    //切换到小云分支

git checkout -b yunhang          //创建并切换到远航分支

13. Merge branches

1.git checkout xiaoyun //切换到xiaoyun分支上

2.git rebase master    //将xiaoyun分支的起始点移动到当前master分支的最后的位置

3.git merge xiaoyun   //将xiaoyun分支内容合并到master上

4.git branch -d xiaoyun   //合并之后 本地删除xiaoyun分支

5.git branch -D xiaoyun   //没合并,但是该分支代码确定不要了 本地删除xiaoyun分支

6.git push

7.git push origin --delete xiaoyun  //删除远程分支

14. When two branches have changed the same file and merged into the main branch, conflicts will occur, and the conflicts need to be resolved manually

vim a.php     //编辑a.php文件内容,编辑的时候 将冲突删除即可

vim进入编辑文件模式,按 i 进行编辑,按esc和:wq退出编辑

cat a.php     //查看a.php文件内容

15. View the merged branch, view as a merged branch

git branch --merged    //查看已合并分支

git branch --no-merged  //查看为合并分支

16. Temporary storage area, for example, I wrote a part of the function in the a branch, because I have not finished writing, do not submit the code, but at this time I need to switch to another branch, I will be prompted that there is no submission, can not switch, then you can change a Branch content for temporary storage

git stash       //添加到暂存区

git stash list  //查看缓存列表

git stash apply //恢复缓存区

git stash drop stash@{0}  //恢复缓存区后,缓存区仍然存在缓存日志,这个命令是删除这些缓存

git stash pop     //恢复缓存区后直接删除这些缓存

17. Labels (when the program is finished a version, you can make a label. For example, version 1.0 and version 2.0)

git tag 1.0

18. Rebase branch merge optimization, move the starting point of the current branch to the last position of the master branch; conflict resolution should be resolved by the branch, not the problem resolved by the master; make the log more concise;

Before optimization

Optimized

19.Fill in the ssh public key

Generate secret key

Using ssh to connect to Github to send commands is more secure and reliable, and it can also avoid the trouble of entering a password every time.

Enter the following code in the command line (windows users use Git Bash)

ssh-keygen -t rsa

Keep pressing the Enter key until the end. The system will ~/.ssh generate a id_rsasum in the directory  id_rsa.pub, namely the key id_rsaand the public key id_rsa.pub.

Add secret key to GitHub

Click the  New SSH key button to add the id_rsa.pub public key content generated above  .

20. Clone the project on git

git clone [email protected]:xiaoyunliu123/meituan.git

21. Associate remote warehouse push code

(1) Create a local library and complete the initial submission

echo "# hd-xj" >> README.md
git init
git add README.md
git commit -m "first commit"

(2) Add remote warehouse

git remote add origin [email protected]:xiaoyunliu123/meituan.git

(3) View the remote library

git remote -v

(4) Push data to remote warehouse

git push -u origin master

(5) Delete the remote warehouse association

git remote rm origin

22. Check out the remote branch to the local

1.git clone                        //检出远程项目

2.git branch -a                    //查看远程分支

3.git pull origin xiaoyun:yuanhang  //检出远程xiaoyun分支到本地的yuanhang分支

 

Guess you like

Origin blog.csdn.net/xiaoyun888_/article/details/110226425