In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/03 Report--
When you use Git for version management, you will not only submit, but sometimes you will need to roll back and resubmit on the basis of fallback. At this time, there are several commonly used commands that need to be used, which are described below.
1. View the submission log
First, let's look at the current command to submit the record:
$git logcommit bfee9d6618bc1deae52ac4a7942b96990bbfe661 (HEAD-> master, origin/master, origin/HEAD) Author: sylan215 Date: Thu Oct 19 15:19:30 2017 + 0800 dddcommit fbb28efb4e156031704abbf015b12c8ef16031c8Author: sylan215 Date: Thu Oct 19 15:15:26 2017 + 0800 revert
If there are too many log, you can add the parameter-- pretty=oneline uses:
$git log-- pretty=onelinebfee9d6618bc1deae52ac4a7942b96990bbfe661 (HEAD-> master, origin/master, origin/HEAD) dddfbb28efb4e156031704abbf015b12c8ef16031c8 revertca0e36b485a3de75e6e11064aecc22ce100652dd new line45dcf1bc797a773ca3dee07fc795ef986d10c346 t5e29356aa7aea31e7e6bce302abbc2259324d806 test2, view command execution record
View the execution record of native commands:
$git reflogbfee9d6 (HEAD-> master, origin/master, origin/HEAD) HEAD@ {0}: reset: moving to bfee9d6618bc1deae52ac4a7942b96990bbfe661bfee9d6 (HEAD-> master, origin/master, origin/HEAD) HEAD@ {1}: commit: dddfbb28ef HEAD@ {2}: reset: moving to fbb28efb4e156031704abbf015b12c8ef16031c8fbb28ef HEAD@ {3}: reset: moving to fbb28efb4e156031704abbf015b12c8ef16031c8fbb28ef HEAD@ {4}: commit: revertca0e36b HEAD@ {5}: reset: moving to ca0e36b485a3de75e6e11064aecc22ce100652ddca0e36b HEAD@ {6}: commit: new line45dcf1b HEAD@ {7}: reset: moving to 45dcf13, use reset for fallback
We can view the previous record in the above two ways and find the version to be rolled back. The fallback version can be expressed in two ways, one is commit id, which is the string of characters, and the other is the serial number of the relative HEAD. Take a look at the command:
$git reset-- hard head ^ head is now at ca0e36b new line$ git reset-- har bfee9dHEAD is now at bfee9d6 ddd
We first rolled back two versions using head ^ ^, and then returned to the latest version using the bfee9d commit id. Note that the HEAD method can only fall back to the old version, not the new version. The commit id method can fall back to any valid id version. As for how to view the id corresponding to the version, please see the git log and git reflog commands introduced at the beginning.
This command can also achieve the effect of discarding all current changes in disguise, and just run git reset-hard HEAD.
After reversing the version, we modify it again and submit it, and we will find the following error:
$git add. $git commit-am "test reset" [master 88b1dc8] test reset 1 file changed, 1 insertion (+), 1 deletion (-) $git pushTo 192.168.252.130:/srv/myfiles.git! [rejected] master-> master (non-fast-forward) error: failed to push some refs to 'git@192.168.252.130:/srv/myfiles.git'hint: Updates were rejected because the tip of your current branch is behindhint: its remote counterpart. Integrate the remote changes (e.g.hint:' git pull...') Before pushing again.hint: See the 'Note about fast-forwards' in' git push-- help' for details.
The solution is to use the command git push-f to solve:
$git push-fCounting objects: 3, done.Compressing objects: 100% (2 bytes 2), done.Writing objects: 100% (3 delta 3), 286 bytes | 286.00 KiB/s, done.Total 3 (delta 0), reused 0 (delta 0) To 192.168.252.130:/srv/myfiles.git + bfee9d6...88b1dc8 master-> master (forced update)
Note: git push-f means mandatory submission, and if used in conjunction with reset, all commit from the latest version to the version of reset will be erased, which should be paid special attention to when working with multiple people.
Specifically, after we pass the command, git long-pretty=oneline can see it more intuitively:
$git log-pretty=oneline88b1dc8cb7228f7d1fe14d510a62201a9d584118 (HEAD-> master, origin/master, origin/HEAD) test resetca0e36b485a3de75e6e11064aecc22ce100652dd new line45dcf1bc797a773ca3dee07fc795ef986d10c346 t5e29356aa7aea31e7e6bce302abbc2259324d806 test
Compared to the top output, the two commit id after commit id ca0e36b485a3de75e6e11064aecc22ce100652dd have been rolled back (fbb28efb4e156031704abbf015b12c8ef16031c8 and bfee9d6618bc1deae52ac4a7942b96990bbfe661).
4. Another gentle way of falling back
Using reset is a direct way to erase commit, and there is another real "fallback" command, revert, which has the effect of deleting changes to the fallback version and creating a new submission based on the current version.
Let's see how it works:
Git log-- pretty=oneline9eecd39b8e6a2109c3678c42dc034db2190840f6 (HEAD-> master, origin/master, origin/HEAD) changee4f5e6920c22b748d765824e0be21015332fafa4 init$ git revert 9eec [master f7c9eb4] Revert "change" 1 file changed, 1 insertion (+), 2 deletions (-) $git log-- pretty=onelinef7c9eb4120d368915a6e5491bf85dc5cd87a424f (HEAD-> master) Revert "change" 9eecd39b8e6a2109c3678c42dc034db2190840f6 (origin/master, origin/HEAD) changee4f5e6920c22b748d765824e0be21015332fafa4 init
Based on the latest version, we rollback the last committed changes, and generate a commit with the fallback version, and generate a new commit id, so that all operational log is properly retained.
Note: the command revert refers to backing back the changes of the specified version, not everything from the specified version to the current version, so if the given commit id is not the latest commit id of the current version, an error will be reported:
Git log-- pretty=oneline45734f3dc12f45e78504bd0fb52ba334c0ae2c9f (HEAD-> master, origin/master, origin/HEAD) test7c82b777a40dfb24fc1bba404be0daa3b3923a95 test revertf7c9eb4120d368915a6e5491bf85dc5cd87a424f Revert "change" 9eecd39b8e6a2109c3678c42dc034db2190840f6 changee4f5e6920c22b748d765824e0be21015332fafa4 init$ git revert 7c82berror: could not revert 7c82b77. Test reverthint: after resolving the conflicts, mark the corrected pathshint: with 'git add' or 'git rm' hint: and commit the result with 'git commit'$ git statusOn branch masterYour branch is up-to-date with' origin/master'.You are currently reverting commit 7c82b77. (fix conflicts and run "git revert-- continue") (use "git revert-- abort" to cancel the revert operation) Unmerged paths: (use "git reset HEAD..." To unstage) (use "git add..." To mark resolution) both modified: test2.txtno changes added to commit (use "git add" and/or "git commit-a")
If, in the figure above, we skip the 45734 modification and want to roll back only the modification of 7c82b, there will be a conflict. At this time, you can either manually modify the conflict, or cancel the revert and specify more than one revert id at a time. The following is implemented using multiple revert id at a time:
Git revert-- abort$ git log-- pretty=oneline45734f3dc12f45e78504bd0fb52ba334c0ae2c9f (HEAD-> master, origin/master, origin/HEAD) test7c82b777a40dfb24fc1bba404be0daa3b3923a95 test revertf7c9eb4120d368915a6e5491bf85dc5cd87a424f Revert "change" 9eecd39b8e6a2109c3678c42dc034db2190840f6 changee4f5e6920c22b748d765824e0be21015332fafa4 init$ git revert 45734 7c82b [master 8140eb0] Revert "test" 1 file changed, 1 insertion (+), 3 deletions (-) [master 191816d] Revert "test revert" 1 file changed, 1 insertion (+), 2 deletions (-) $git log-pretty=oneline191816d84c02a4ba591d3739739ddd0df114d7f1 (HEAD-> master) Revert "test revert" 8140eb0f69493f1a6306b0e92822f07c049a7a50 Revert "test" 45734f3dc12f45e78504bd0fb52ba334c0ae2c9f (origin/master, origin/HEAD) test7c82b777a40dfb24fc1bba404be0daa3b3923a95 test revertf7c9eb4120d368915a6e5491bf85dc5cd87a424f Revert "change" change
At this point, if we look at the file, we will see that the contents of 45734 and 7c82b have been rolled back, and two new commit have been generated (each commit id fallback will generate a separate record).
In particular, in order to ensure the effectiveness of revert, it is recommended to minimize the submission of uncoupled files every time you submit changes, and batch submission can be more beneficial to the future revert.
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.