(Big Data Engineer Learning Path) Step three Git Community book----Intermediate skills (top)

Source: Internet
Author: User

Ignoring some files 1. Ignoring certain files

Projects often generate files that do not require tracking (track) in a git system. Typical is the file generated during the build process or the temporary backup file generated by the programmer. Of course, you do not track these files, you can usually not use "git add" to add them to the index. But this can quickly become a chore, and you find that the project is littered with untraceable (untracked) documents; This also makes "Git add" and "Git commit-a" virtually useless, and the output of the git status command will also have them. You can add a file called ". Gitignore" to your top-level working directory to tell the GIT system which files to ignore, and here's an example of the file content: lines starting with ' # ' are treated as comments. Ignores all file names that are foo.txt.

foo.txt

All generated HTML files are ignored.

*.html

The foo.html is manually maintained, so the exception is.

!foo.html

Ignore All. O and. a files.

*.[oa]
Third, Rebase1.rebase

Suppose you now create a branch called "MyWork" based on the remote branch "origin".

$ git checkout -b mywork origin

Now let's make some changes in this branch and then generate two commits (commit).

$ vi file.txt$ git commit$ vi otherfile.txt$ git commit

But at the same time, some people have made some changes to the "origin" branch and have made submissions. This means that the two branches of "origin" and "mywork" each "Go forward" and "fork" between them. In this case, you can use the "pull" command to drop the changes on the "origin" branch and merge with your changes; The result looks like a new "merged commit" (merge commit): But if you want the "mywork" branching history to look like it hasn't been merged, , you might be able to use Git rebase:

$ git checkout mywork$ git rebase origin

These commands will cancel each commit (commit) in your "mywork" branch and temporarily save them as patches (patches), and then update the "mywork" branch to the newest "origin" branch, in the ". Git/rebase" directory. Finally, the saved patches are applied to the "MyWork" branch. When the ' mywork ' branch is updated, it points to these newly created commits, and those old commits are discarded. If you run the Garbage collection command (pruning garbage collection), these discarded commits are deleted. In the process of rebase, there may be conflicts (conflict). In this case, Git will stop rebase and will let you resolve the conflict, after resolving the conflict, use the "git-add" command to update the index of these content, then you do not need to execute git-commit, as long as the execution:

$ git rebase --continue

This way git will continue to apply the remaining patches. At any time, you can use the--abort parameter to terminate the action of Rebase, and the "MyWork" branch will return to the state before the start of rebase.

$ git rebase --abort
Iv. Interactive rebase1. Interactive rebase

You can also choose to have interactive rebase. This approach is typically used to rewrite the commits before they are pushed elsewhere. Interactive Rebase provides an easy-to-use way for you to split, merge, or reorder your submissions before sharing them with others. You can also use interactive rebase to clean up commits that are pulled from other developers when you apply them locally. If you want to modify part of the commit during rebase, you can add the '-I ' or '--interactive ' parameter to the ' git rebase ' command to invoke the interactive mode.

$ git rebase -i origin/master

This command performs interactive rebase operations on all commits that have been pulled from the Origin repository or pushed to Origin since the last time they were taken. If you want to see the commit that will be rebase, you can use the following log command:

log github/master..

Once you have finished editing the submission and exited the editor, the new commit and submission information will be saved. If you specify an ' edit ' operation, Git will do the same, but before the next commit, it will return to the command line and let you fix the commit or make changes to the submission. For example, if you want to split a commit, you need to specify the ' edit ' action on that commit: You will go to the command line, revoke (revert) the commit, and then create two (or more) new commits. Assuming that the commit 21D80A5 modifies two files, file1 and file2, you want to put these two changes into different submissions. You can do the following after entering the command line:

$ git reset HEAD$ git add file1$ git commit -m ‘first part of split commit‘$ git add file2$ git commit -m ‘second part of split commit‘$ git rebase --continue

The last function of interactive rebase is to discard commits. If you delete a row instead of specifying ' pick ', ' squash ', and ' edit ', Git removes the commit from the history

V. Interactive add 1. Interactive add

Interactive add provides a friendly interface to manipulate the GIT Index (index) and also provides the ability to visualize the index. You can use this feature simply by typing ' git add-i '. GIT lists all the modified files and their status.

$ git add -i

In this example, we can see that there are 5 modified files that have not been added to the index (unstaged) and can even see the number of rows increased and decreased for each file. Followed by an interactive menu that lists the commands we can use in this mode. If we want to stage these files, we can type ' 2 ' or ' U ' into update mode. We can then decide which files to add to the index by typing the scope of the file (in this case, 1-4).

What now> 2Staged unstaged path 1:unchanged +4/-0 assets/stylesheets/style.css 2:unchanged +23/-11 layout/b Ook_index_template.html 3:unchanged +7/-7 layout/chapter_template.html 4:unchanged +3/-3 script/p DF.RB 5:unchanged +121/-0 TEXT/14_interactive_rebasing/0_ interactive_rebasing.markdownupdate>> 1- 4 staged unstaged path* 1:unchanged +4/-0 assets/stylesheets/style.css* 2:unchanged +23/-11 layout/book  _index_template.html* 3:unchanged +7/-7 layout/chapter_template.html* 4:unchanged +3/-3 script/pdf.rb 5: Unchanged +121/-0 TEXT/14_interactive_rebasing/0_ interactive_rebasing.markdownupdate>>  

If you type enter, I'll go back to the main menu and see that the state of the specified file has changed:

What now> status           staged     unstaged path  1:        +4/-0      nothing assets/stylesheets/style.css  2: +23/-11 nothing layout/book_index_template.html 3: +7/-7 nothing layout/chapter_template.html 4: +3/-3 nothing script/pdf.rb 5: unchanged +121/-0 text/14_Interactive_Rebasing/0_ Interactive_Rebasing.markdown

Now we can see that the first 4 files have been staged, but the last one is not. Basically, this is a more compact way to view the state, and the actual information is consistent with the fact that we run ' git status ' on the command line:

$ git status
Vi. Storage 1. Storage

When you are doing a complex job, you find a bug that is not relevant to your current job but is annoying. You want to fix the bug and do the work at hand, then you can use Git stash to save the current state of work, after you fix the bug, the "anti-storage" (Unstash) operation can go back to the previous work.

$ git stash save "work in progress for foo feature"

The above command will save your local changes to the storage (stash) and then reset all your working directory and index to the state of the last commit of your current branch. Well, you can start your repair work now.

-a -m "blorpl: typofix"

After you fix the bug, you can use Git stash apply to revert back to the previous working state.

$ git stash apply
2. Storage queue

You can also use the ' git stash ' command multiple times to add a ' storage ' (stash) to the storage queue for the current modification once per execution. Use the ' Git Stash list ' command to view your saved ' storage ' (stashes):

list

You can use a command like ' git stash ' to apply [email protected]{1} ' for any ' storage ' (stashes) in the queue. ' Git stash clear ' is used to empty this queue.

Seven, git tree name 1.Git tree name

There are many ways to name a commit (commit) or other Git object without a 40-byte-long Sha string. In git, these names are called ' Tree Names ' (treeish).

2.Sha Short Name

If one of your commit (commit) Sha names is ' 980e3ccdaac54a0d4de358f3fe5d718027d96aae ', Git treats the following string as equivalent:

980e3ccdaac54a0d4de358f3fe5d718027d96aae980e3ccdaac54a0d4980e3cc

As long as your ' Sha short name ' (partial sha) is not duplicated (unique), it does not conflict with other names (if you use more than 5 bytes that is hard to repeat), Git also automatically complements the ' Sha short name ' (Partial sha).

3. Branch, Remote or label

You can use branch, remote, or tag names instead of the SHA string names, which are just pointers to an object. Assuming that your Master branch is currently committed (commit): ' 980e3 ', now push it to origin and name it tag ' v1.0 ', then the following string will be considered equivalent by git:

980e3ccdaac54a0d4de358f3fe5d718027d96aaeorigin/masterrefs/remotes/origin/mastermasterrefs/heads/masterv1.0refs/tags/v1.0

This means that you perform the following two commands with the same output:

log master$ git log refs/tags/v1.0
4. Date identifiers

Git's Reference log (Ref log) allows you to do some ' relative ' query operations

master@{yesterday}[email protected]{1 month ago}:

The first command above is the abbreviation for the ' master ' branch's yesterday State (head). Note: This command is executed even on two warehouses that have the same master branch point, but if the two warehouses are on different machines, the execution results are likely to vary.

5. Sequential identifiers

This format is used to express the Nth commit (ref) preceding a point.

master@{5}

The above expression represents the 5th commit (ref) in front of master.

6. Multiple Parent objects

This can tell you the nth Direct parent commit (parent) of a commit. This format is particularly useful when merging commits (merge commits), so that there are more than one direct parent object (Commit object) for the commit objects (direct parent).

master^2
7. Wave number

The tilde is used to identify the nth-level entropy (ancestor) Parent object (Nth grandparent) of a commit object. For example:

master~2

The first parent object that represents the first parent of the commit object pointed to by master (translator: You can understand it as direct descendant Grandpa:)). It is equivalent to the following expression:

master^^

You can also add these ' identifiers ' (spec), the following 3 expressions all point to the same commit (commit):

master^^^^^^master~3^~2master~6
8. Tree Object pointer

If you are still impressed with the first chapter of the Git object model, remember that the Commit object is a pointer to a tree object. If you're going to get a commit object (Commit object) pointing to the tree object SHA string name, you can add ' {tree} ' after the ' tree name ' to get it:

master^{tree}
9. Binary identifiers

If you want the SHA string name of a binary object (BLOB), you can get it by adding a binary object (BLOB) corresponding to the file path after the ' Tree name ' (treeish).

master:/path/to/file
10. Interval

Finally, you can use the ".." To refer to the interval between two commits (commit). The following command gives you all commits (commit) between "7b593b5" and "51bea1" except for "7b593b5" (Note: 51BEA1 is the most recent commit).

7b593b5..51bea1

This includes all commits (commits) that start with 7b593b. Translator Note: equivalent to 7b593b. HEAD

7b593b..
Viii. Summary

This section is a middle-level knowledge of git, and you can add indexes by configuring the. gitignore file to ignore the file, and also explaining git rebase, git stash, and the git tree name.

(Big Data Engineer Learning Path) Step three Git Community book----Intermediate skills (top)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.