git git-related operations and frequently used tool operations

 

1. git structure

The core is different from svn git version control tools such that each local library does not just save remote indexing, but save all the contents of the remote, every local library can be independent as a remote library.

The structure and the operation target git common commands shown below:

RemoteRepository: remote library on a remote server
LocalRepository: local library, on a personal PC
Stage: Staging, save to the file index, if there is a submission that contains a lot of features, modify future will be very troublesome, then you can use once the temporary submission.
WorkSpace: Workspace
 

 

 

2. Common operation command, the specific operation can view https://git-scm.com/book/zh/v2

git add: save changes from the working directory to the staging area

git commit: save changes to a local warehouse from scratch

git push: save changes from the local repository to the remote repository

git clone: ​​Create a local warehouse to save all data to a remote repository local repository

git fetch: will modify the remote repository to the local repository update

git merge: the merge a branch to another branch

git pull: git fetch + git merge, first save remote updates to the local repository, then compare local branch and a remote branch, if there is no conflict, merger, or prompt conflict to be resolved

git branch: create a branch

git checkout: branch switching

git rebase: for the base, with the git merge function is similar, but the record will be cleared, so that the recording looks clearer. Not recommended, because it may cause data loss

git stash: save your modified data, then your work just like the remote's library

git patch: The patch your changes, you can save up, you can also use to others

git revert: Change your current working directory pointed to commit, such as a library commit a total of three times, and now you want to continue to develop on the basis of the second commit, you can use this command to change the head

git SubMoule add / update: subdirectories added and updated, this is generally for the subdirectory is another library, but my projects need to reference it

 

3. git directory

When we use the git tool will generate a .git hidden folder, all operations are stored in the .git folder, as shown in Figure

If there is reference to a subdirectory, will be here to generate a modules folder, in fact, is another point to go see .git folder

 

You can see the details link: https: //blog.csdn.net/mayfla/article/details/78653396,https: //blog.csdn.net/a19881029/article/details/42245955

I speak here mainly focus on the next part

(1) config file, save the data remote and local branches

(2) refs folder to save the latest commitID remote libraries and local libraries, the corresponding folder heads and remotes

    logs / refs folder holds the record date last modified remote libraries and local libraries, the corresponding folder heads and remotes

The difference between (3) fetch and pull the

fetch will modify and modify records commitID remote library, then merge modifies commitID and modify records local library

pull will also revise and modify records commitID remote libraries and local libraries

 

4. Create a branch, modify, merge into the trunk process

(1) Master backbone updated three times, respectively, a, b, c

 

(2) Feature start creating branches in the node c, then switch to the branch

  git checkout -b feature

(3) This branch is created in the local repository, push it to the remote, then there will be such a remote branch

  git push

(4) When you work on this branch, created f, g two commit, at this time remote trunk was also submitted new commit d and h

(5) At this point you have completed your work, need to be merged into the trunk, you need to merge locally, this step is to update to the latest branch, and then used for testing

  Switch to the main branch master, then pull to ensure the latest, and then switch to the branch feature, and then merged into the main branch of the test, then push

  git checkout master
  git pull
  git checkout feature
  git merge master
  test the function
  git push

  此时本地和远程的库一致,对应的master和feature如下图所示

(6)此时分支Feature其实已经是最新的了,我们只需要把Master跟feature一样就行 

  切换到主干,主干合并分支,然后push

  git checkout master

    git merge featurer

    git push

 

 5.常用git工具

Fork操作(tortoiseGIt跟它操作类似):

git add : changes里面的stage和unstage就是保存到暂存和从暂存里面删除,如图

git commit : changes里面点击stage,然后右下角输入commit信息,然后点击commit

git push : 左边Branches里面选中对应的branch,右击push,或者直接点击左上角的push

git clone : 菜单栏选择File->Init New Respository

git fetch : 选中当前分支,点击菜单栏下方的fetch

git merge : 选中需要合并的源分支,然后选中目标分支,右击选中Merge into(比如将A合并到B,B是当前分支,然后选中A,右击Merge Into B)

git pull :类似git push,右击fast-forward pull

git branch : 点击右上角New Branch

git checkout : 左边Branches里面选中对应的branch,右击CheckOut

git stash:当你的分支有修改时,Changes里面会有提示,此时你可以点击菜单栏下方的Stash,然后保存,需要使用的时候点击左边的stashes里面选中你保存的,右击apply

 

git revert : 在All Commits页面,选中你需要切换的commit,右击reset 。。to here,然后选中mix或者hard

git patch : 再Changes页面里面选中修改的change然后右击Save as patch,此时你可以把change discard掉,去干别的事,也可以使用Reset..to here切换head,然后做别的事,使用patch,在菜单栏里面选中apply patch,此时要确保你的head一定要和保存patch时一致,否则会报错

git SubMoule add/update : 直接在最左边,Submodules右击

 

 

 

6. 小提示

当有时你不小心把你的一个文件或一个目录删掉了,你想从远程拉下来

打开命令行,定位到目录

一个文件 : git checkout a.cs
当前目录 : git checkout .

 

Guess you like

Origin www.cnblogs.com/xiaojidanbai/p/11331367.html