编程知识 cdmana.com

Common git commands

Preface

Six months of internship , It summarizes some commonly used github command :
The way our company uses is to put the company library first Fork Come down , After modifying your local library push To your own remote library , And then submit PR, After others passed, they merged . And you don't usually have to merge, While using rebase send git The tree looks like a straight line ( I have a shallow and thorough understanding of ), The code is developed with VSCode, There's also management on it git Tools for ( This works well on company computers ,but not mine)

Reference resources

These blogs really helped me a lot , Thank you very much .

technological process :

  • Application account , Add public key . Our company uses ssh, This application authority Use SSH Connect to GitHub. After a long time , I'm not going to repeat it all here ( Actually, I forgot ).
  • Detailed process :fork -> clone -> Create a branch -> Modify the code -> Submit -> Submit PR

You can see github---- Submit to the open source framework pr The process of

A few commands that I often use

  • git add .
  • git commit
  • git status
  • git fetch upstream
  • git rebase upstream master
  • git push origin master -f
  • git rebase -i HEAD~n
  • git reset
  • git checkout -b branchName
  • git branch -d branchName

A few commands that are not commonly used

VScode Self contained or downloadable tools
VScode Management tools

The following operations have not gone through fork Of , And in master The process of direct operation under the branch . If you want to switch branches , It can be executed :git checkout -b checkName.
PS: I was at the beginning master Under the branch , Later, we need to PR It's a lot more , I used the branching method slowly . It's so convenient . and VScode It's easy to operate with your own tools Screenshot from 2020-09-25 10-34-20.png

Get to the point

git add

Change the file from the workspace workspace Add to the staging area stash Inside ,commit The necessary work before .git diff Command to see the difference between the two ( I don't use it very often )
git add . : Add all changed files to stage Inside
git add fileName
git add

git commit

Add the files in the cache to the repository ,git diff head You can see the difference between the two , It is best to git commit -m "commit Information ", If direct git commit There may be errors , in addition commit message standard

git commit
And then I executed git add. Submit the remaining two documents together .
perform git log View submission records
git log

Connect to the remote library

git remote -v You can see which library is remotely connected

git push

git push origin master // Submit your own commit Remote submission to your own library master Under branch .master You can also change it to another branch name
Then you can submit PR 了

git rebase

Commonly used in
1. Submit code multiple times , But in the end, only one commit Of . Reference resources rabase Merge multiple commit
2. Submit pr Before finishing git Trees . Every time you submit, you need to guarantee that rebase upstream/master after ( Merge the remote library's with your own ) There is no conflict , But this merger is different from merge,rebase It's like connecting to your own remote branch master after , So the whole commit tree is a straight line .
I am here 1.txt It was modified in : This can be done in the following way commit modify 1.txt
commit after
If you want to merge several commit, For example, the second submission and the first modification merge , It can be executed
git rebase -i HEAD~2
squash If you want to keep that one commit Information , namely -m Those behind
 The merger was successful ,very nice

版权声明
本文为[Nine is me]所创,转载请带上原文链接,感谢
https://cdmana.com/2020/12/20201225122641876L.html

Scroll to Top