One, Tracking branch 1. Track Branches
The ' Trace branch ' in Git is used to contact local and remote branches. If you perform push (push) or pull on the ' Trace branch ' (Tracking Branches), it automatically pushes (push) or pulls (pull) onto the associated remote branch. If you often want to branch from the remote repository to the local, and do not want to be cumbersome to use the "git Pull" format; Then you should use ' Trace branch ' (Tracking Branches). The git clone ' command automatically builds a ' master ' branch locally, which is ' Origin/master ' 's ' Tracking branch '. The ' Origin/master ' is the ' master ' branch of the Clone repository. You can manually create a ' tracking branch ' by adding the '--track ' parameter when using the ' Git branch ' command.
$ git branch --track experimental origin/experimental
When you run the command:
$ git pull experimental
It automatically fetches (fetch) content from ' origin ' and merges the remote ' origin/experimental ' branch into the local ' experimental ' branch. When you push a modification to origin, it pushes the changes in your local ' experimental ' branch into the ' experimental ' branch of Origin without specifying it (origin).
Third, use git grep to search 1. Search using git grep
It is convenient to use the git grep command to find a piece of text inside a git library. Of course, you can also search with the ' grep ' command under UNIX, but the ' git grep ' command allows you to find them without having to check out (checkout) history files. For example, if you want to see the git.git in this repository where every ' xmmap ' function is used, you can run the following command:
grep xmmap
If you want to display line numbers, you can add the '-N ' option:
grep -n xmmap
If we want to display only the filename, we can use the '--name-onley ' option:
grep --name-only xmmap
We use the '-C ' option to see how many lines match in each file (line matches):
grep -c xmmap
Now, if we are looking for content in a particular version of the Git repository, we can add the tag name (tag reference) to the end of the command line as follows:
grep xmmap v1.5.0
We can also combine some search criteria, and the following command is to find where we define ' sort_dirent ' in the repository.
-e ‘#define‘ --and -e SORT_DIRENT
Not only can I perform A and (both) conditional search operation, but I can also perform a "or" (either) conditional search operation.
-e ‘#define‘ -e SORT_DIRENT
We can also find a line of files that meet one condition (term) and one of two conditions (terms). For example, we want to find out the name contains a constant definition of ' PATH ' or ' MAX ':
-e ‘#define‘ --and \( -e PATH -e MAX \)
Iv. git undo Operations-Reset, checkout and undo 1. Fix errors in uncommitted files (reset)
If your current working directory is mess, but you haven't submitted them yet; You can use the following command to get the working directory back to the state it was last submitted to: committed
reset --hard HEAD
This command empties all uncommitted content in your working directory (this does not include files that are not under version control, of course, untracked file). On the other hand, this makes the display of the Git diff and git diff--cached commands empty. If you just want to restore a file, such as "hello.rb", you need to use git checkout
$ git checkout -- hello.rb
This command checks the HELLO.RB from head and restores it to its unmodified appearance.
2. Fix errors in submitted files
If you have made a commit, but you regret it immediately, there are two distinct ways to deal with it: create a new commit and undo the old commit changes in the new submission. This is quite true when you have published the code. You can also modify your old commit. But if you've already released the code, don't do it. Git does not deal with a situation where the history of a project changes, and if a branch's history is changed, then it cannot be merged properly. Create a new commit to fix the error create a new, undo (revert) the pre-modified commit (commit) is very easy; Just pass the name of the error commit (reference) as a parameter to the command: git revert is available; The following command demonstrates how to undo the most recent commit:
$ git revert HEAD
This creates a new commit that undoes the last commit (HEAD), and you have the opportunity to modify the commit comment information in the new commit. You can also undo earlier changes, and the following command undoes the "last" (Next-to-last) Commit:
$ git revert HEAD^
In this case, Git tries to undo the old commit and then leave the full old commit before the version. If your recent changes overlap (overlap) with the changes you want to undo, you will be asked to resolve the conflict manually (conflicts), just as it did when you resolved the merge. Translator Note: Git revert actually does not create a commit directly, put the contents of the revoked file into the index, you need to execute the git commit command, they will become a real commit. Modify the commit to fix the error if you have just made a commit, but you want to modify the submission immediately; Git commit now supports a parameter called--amend, which allows you to modify the commit (HEAD commit) just now. This mechanism allows you to add some new files or modify your commit comment (commit message) before the code is released. If you find an error in the old commit (older commit), it is not published to the code server yet. You can use the interactive mode of git rebase command, "git rebase-i" will prompt you to make relevant changes in the edit. This is actually to let you in the process of rebase to modify the submission.
V. Maintenance of GIT1. Ensure good performance
In a large warehouse, Git saves disk and memory space by compressing historical information. The compression operation is not automatic, and you need to perform the Git GC manually:
$ git gc
Compression is time-consuming, and it's best to run a git GC command when you have no other job.
2. Maintain reliability
Git fsck runs a consistency check on some warehouses and reports if there are any problems. This is also a time-consuming operation, and the usual warning is "dangling objects" (dangling objects).
$ git fsck
"Dangling objects" (dangling objects) is not a problem, but the worst case scenario is that they take up more disk space. Sometimes they are the last glimmer of hope to get the lost job back.
Vi. establishment of a public warehouse 1. Building a public warehouse
Suppose your personal warehouse is in the directory ~/proj. We'll clone a new "bare repository" and create a flag file to tell Git-daemon it's a public repository.
clone --bare ~/proj proj.git$ touch proj.git/git-daemon-export-ok
The above command creates a proj.git directory with a "Bare git repository"-that is, only the contents of the '. Git ' directory, without any files checked out (checked out). The next step is to copy the Proj.git directory onto the host you intend to use to host the public repository. You can use SCP, rsync or any other way.
2. Exporting a git repository via the GIT protocol
This is the recommended way to export a git repository with a git protocol. If there is an administrator on this server, TA will tell you which directory to put the warehouse in, and "git://URL" in addition to the Warehouse directory section. All you have to do now is start git daemon; It will listen on port 9418. By default it will allow you to access all GIT directories (see if there are git-daemon-export-ok files in the directory). If you use some directories as Git-daemon parameters, then Git-daemon restricts users to access only those directories through the GIT protocol. You can run Git-daemon in inetd service mode; Click Git daemon to view help information.
3. Exporting a git repository via the HTTP protocol
The GIT protocol has good performance and reliability, but if a Web server is already in place on the host, using the HTTP protocol (git over HTTP) may be easier to configure. You need to put the new "bare repository" in the accessible directory of your Web server and make some tweaks to get the extra information that the Web client needs.
$ mv proj.git /home/you/public_html/proj.git$ cd proj.git$ git --bare update-server-info$ chmod a+x hooks/post-update
$ git clone http://yourserver.com/~you/proj.git
clone http://yourserver.com/~you/proj.git
Vii. establishment of a private warehouse 1. Access to the warehouse via SSH protocol
The easiest way is to access git (git over ssh) through the SSH protocol. If you have an SSH account on a machine, you can simply put the "Git naked Repository" into any directory that you can access via SSH and then use it as easily as you would for SSH login. Suppose you now have a warehouse and you want to build it into a private repository that can be accessed online. You can use the following command to export a "naked warehouse" and then use the SCP command to copy them to your server:
$ git clone --bare /home/user/myrepo/.git /tmp/myrepo.git$ scp -r /tmp/myrepo.git myserver.com:/opt/git/myrepo.git
If other people also have an SSH account on the myserver.com server, TA can clone the (clone) code from this server:
clone myserver.com:/opt/git/myrepo.git
The above command will prompt you to enter the SSH password or use the public key.
Viii. Summary
This section is about tracking branches, searching with git grep, git undo (git Reset, git checkout, git revert), maintaining git (git gc, git fsck), and building public and private repositories.
Nine, practice
Please build a public repository for your small partners to access.
(Big Data Engineer Learning Path) Step three Git Community book----Intermediate skills (bottom)