In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
The main content of this article is "how to use the Git command quick check table", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn "how to use the Git command quick check table"!
Git quick look-up table
Save changes without committing them
This is a simple example, simply run:
Git stash
Then, to restore these stored changes and ensure that you are in the same branch, you can run:
Git stash apply
Kill all uncommitted changes
Sometimes you want to try some methods, but the results are not good. To get rid of all changes made since the last commit, simply run:
Git checkout.
To clear only changes in a specific file or directory. You can replace it with a list of files and / or directories from which you want to remove changes.
Synchronize fork with the main warehouse
When branching a project, be sure to keep it up-to-date to avoid complex merge conflicts when making a request, or just make sure you have all new features and security patches.
Therefore, this is the way to synchronize the fork:
(1) add a remote warehouse
Get the address of the upstream (main) repository from the location of the branch. Then run the following command to replace URL:
Git remote add upstream
You can check whether it is valid by running git remote-v.
(2) synchronize fork with upstream warehouse
To derive synchronously, get the upstream repository:
Git fetch upstream
Then, on the branch (usually the primary node) with which you want to synchronize, run:
Git merge upstream/master
Or git resets the upstream / primary server according to the policy you choose.
Delete the last X submission
Make some submissions that you eventually need to restore? You can do this in two ways:
Git reset HEAD~2 # undo the commits but keep the changes git reset-- hard HEAD~2 # undo the commits and discard changes
Use the second option as if the submission never happened.
You should replace 2 with the number of submissions you want to return from the latest submission (HEAD).
Compress various submissions into one (no need to reset!)
If you want to get rid of all revision error submissions and merge them all into one, you can use the following methods:
Git reset-soft HEAD~2 & & git commit-m "your message"
Remember to replace 2 with the number of submissions you want to count from HEAD.
Check out the status of the project on the last submission
To go back and view the project status of a given submission in the past, first run git log to view the submission history, and then select the submission to return.
Then, copy its hash and run only git checkout. This will put you in detach head mode. To return, simply check out the branch by name.
Ignore files that have been added to Git
We've been there-add or submit things we shouldn't have. To delete a file from the Git trace and keep it on the system, simply do the following:
Git reset & & echo > > .gitignore
Add to the submission after submission
If you want to change the submission message or add a new file to it, you can use git ammend.
To change the message, use:
Git commit-- amend-m "
And add a new file to the previous submission:
Git add & & git commit-- amend
Note that this "saves the hassle of creating a new submission", but it does actually create a new submission in the background. Therefore, you should do this only if the changes have not been pushed to the remote repository.
Delete a file from Git and trim its entire history
If you have ever pushed sensitive data to a remote repository (for example, on GitHub), you need to delete not only the file from the Git trace, but also its entire history.
You should no longer use this data, for example, if you use API keys, passwords, etc.
The process of doing this is not the easiest, but GitHub has written a full-page tutorial, so I think I should link it here.
Remove sensitive data from the repository-GitHub.
Document merge conflict resolution
To avoid resolving the same exact merge conflict multiple times, you can enable Git caching for merge conflict resolution. This will store the resolution of the merge conflict, and if it occurs again, the same conflict will be resolved automatically:
Git config-global rerere.enabled true
Learn more about this content on Git Docs.
Submission on the wrong branch
If you commit on the wrong branch, you should be able to use our knowledge about deleting the submission to resolve the problem, as follows:
Git branch & & git reset HEAD~2-- hard
This creates a new branch and removes the specified number of commits from the current branch to which you mistakenly added them.
If you actually want these submissions to be made on an existing branch instead of a new one, you can do the following:
Git checkout & git merge git checkout & & git reset HEAD~2-- hard
However, if you cannot merge, you can use git cherry-pick, as follows:
Git checkout git cherry-pick ~ 2 git checkout & & git reset HEAD~2-- hard
Change the branch name
To change the name of the branch, use git branch-m. You can change the name of the current branch:
Git branch-m
Or change the name of any branch:
Git branch-m
Find a submission with errors
If you encounter a problem that has nothing to do with the submission, you need to determine which kind of submission caused the problem in the past. This is common in tests, for example, when you fail because of a test that has nothing to do with your work.
In this case, to find a "bad" submission, you can use git bisect.
It works as follows:
Start the process
Git bisect start
Mark the current submission as "bad"
Git bisect bad
Mark past submissions as "good"
For example, use git log to find past submissions where things go as expected (that is, good). Then, run:
Git bisect good
go halves on a fifty-fifty basis!
You should now receive the following message:
Bisecting: 2 revisions left to test after this (roughly 3 steps) [6ca4a67aeb4b0d9835ecf15e44505c48f93642c9] my-branch
The numbers, hashes, and branch names will naturally be different from yours.
What Git is doing here is to complete the commit step by step until the broken submission is found. You do not need to run git checkout because it has been handled for you.
At each submission, everything should be checked to see if everything is normal. If not, use git bisect bad to mark the submission as an error. If so, use git bisect good to mark it as good.
After marking the submission as good, Git takes you to the first "bad" submission (that is, the last one you marked as bad) so that you can investigate the error correctly. When you are done, simply return the head of the branch by checking out the git checkout and resolve the problem.
At this point, I believe you have a deeper understanding of "how to use Git command quick look-up table". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.