In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
In this issue, Xiaobian will bring you about how to write the code that was forced to push missing in Git. The article is rich in content and analyzed and described from a professional perspective. After reading this article, I hope you can gain something.
preface
Git is a distributed version control system that is easy to learn and difficult to master. It is often used by our code farmers for code management. If you don't know Git yet, it is recommended to first understand it through Liao Xuefeng's Git tutorial, and then look at this article, because this article is mainly based on the use of skills, and will not explain too much on basic nouns.
Recover missing codes from forced push
In the normal development process, it is inevitable that sometimes for various reasons (such as the need to use git rebase), it is necessary to use git push -f, which is forced to push, and this command overrides the remote branch.
However, if the operation is improper, it will be easy to overwrite the previous commit submitted by the small partner. Don't panic. This does not mean that your small partner's commit will never be found. In most cases, they can still be recovered.
git reflog can view all the operation records of all branches (including commit and reset operations), including deleted commit records, git log can not view deleted commit records
Although there is reflog, but because Git will regularly gc (recycle), clean up reflog, so do not wait too long to recover after being overwritten, otherwise you may really not be able to find it.
operation method
Back up data from the current workspace
You can back up the code you're writing using commands like git stash
On the command line type git reflog/git log -g
Show all historical actions and find the commit you need (including deleted commit records, git log cannot view deleted commit records)
2.1 Force a rollback to the commit that was deleted at the time
git reset --hard
2.2 or directly
git cherry-pick
Just bring back the version of the job that was there. But if there is conflict, deal with it.
Forcing remote branches
git push -f origin
If the reason for the commit loss is not recorded in the reflog, such as running rm -Rf .git/logs/, because the reflog data is stored in the.git/logs/directory, then there is no reflog.
You can use the git fsck tool, which checks the data integrity of the repository. If the--full option is specified, the command displays all objects that are not referenced (pointed to) by other objects:
It can then be restored in the same way, by creating a branch to the SHA.
Are you no longer panicking about pushing git push-f?
The above is how to write the code to restore the missing push in Git shared by Xiaobian. If there is a similar doubt, please refer to the above analysis for understanding. If you want to know more about it, please pay attention to the industry information channel.
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.