In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article is to share with you what are the tips in using git. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Git is an open source distributed version control system for efficient and high-speed version management of projects ranging from very small to very large.
1. Automatic error correction in Git
Each of us makes spelling mistakes from time to time, but if you enable Git's automatic error correction feature, you can have Git automatically correct some of the typing error subcommands. Suppose you want to check the status with the command git status, but you happen to type git stats incorrectly. Normally, Git will tell you that 'stats' is not a valid command:
$git statsgit: 'stats' is not a git command. See 'git-- help'.The most similar command isstatus
To avoid similar situations, you only need to enable automatic error correction in your Git configuration.
$git config-global help.autocorrect 1
If you only want to work on the current warehouse, omit the option-global.
This command enables automatic error correction. You can see a detailed description of this command in the corresponding Git official documentation [1], but trying to type the error command above will give you an intuitive understanding of what this setting does:
$git statsgit: 'stats' is not a git command. See 'git-- help'.On branch masterYour branch is up to date with' origin/master'.nothing to commit, working tree clean
In the above example, Git directly runs the first of its suggested commands, git status, rather than showing you its suggested subcommands.
2. Count the submissions
There are many reasons why submissions need to be counted. For example, some developers use the submission count to determine when to increment the project build sequence number, while others use the submission count to get an overall sense of the progress of the project.
Counting submissions is fairly simple and straightforward, and here is the corresponding Git command:
$git rev-list-count branch-name
In the above command, the parameter branch-name must be a valid branch name in your current warehouse.
$git rev-list-count master32 $git rev-list-count dev343, warehouse optimization
Your code repository is valuable not only to you, but also to your organization. With a few routines, you can keep your warehouse clean and up-to-date. Using the .gitignore file [2] is one of these best practices. By using this file, you can tell Git not to save files that do not need to be recorded, such as binaries, temporary files, and so on.
Of course, you can also use Git's garbage collection to further optimize your warehouse.
$git gc-prune=now-aggressive
This command is helpful when you and your team often use pull or push operations.
It is an internal tool that cleans up inaccessible or "suspended" Git objects in your repository.
4. Back up the untracked files
Most of the time, it is safe to delete all untracked files. But there is often a scenario where you want to delete these untracked files and also want to make a backup in case you need it later.
Git combines some Bash commands and plumbing operations that allow you to easily create zip packages for untracked files.
$git ls-files-- others-- exclude-standard-z |\ xargs-0 tar rvf ~ / backup-untracked.zip
The above command generates a zip file named backup-untracked.zip (of course, files ignored in .gitignore are not included).
5. Know your .git folder
Each warehouse has a .git folder, which is a special hidden folder.
$ls-a. ... .git
Git works mainly through two things:
The current working tree (the status of the files you currently checked out) the folder of your Git repository (to be exact, the location of the .git folder that contains version information) this folder stores all the reference information and other important details such as configuration, warehouse data, HEAD status, logs, and so on.
Once you delete this folder, although your source code has not been deleted, there will be no remote information such as your project history. Deleting this folder means that your project (or at least local replication) is no longer under version control. This means that you cannot track your changes; you cannot pull or push from a remote warehouse to a remote warehouse.
Generally speaking, there is not much you need or should do with your .git folder. It is managed by Git and is a restricted area most of the time. However, there are some interesting artifacts in this folder, such as the current HEAD status.
$cat .git / HEADref: refs/heads/master
It also implies a description of your warehouse:
$cat .git / description
This is an unnamed repository; you can name it by editing the file 'description'.
The Git hook folder, along with some examples of hook files, is also here. Refer to these examples and you can see what Git hooks can do. Of course, you can also refer to the introduction to Git hooks written by Seth Kenlon [3].
6. Browse the files of another branch
Sometimes you want to browse the contents of a file under another branch. This can be achieved with a simple Git command without even having to switch branches.
Imagine that you have a file named README.md [4] and it is on the main branch. You are currently working in a branch called dev.
Use the following Git command on the terminal.
$git show main:README.md
Once you execute this command, you can see the contents of the file on the main branch on your terminal.
Search in Git [/ yiji] 7. Search in Git [/ search] you can search like a professional in Git with a simple command. What's more, even though you're not sure which submission or branch your changes are on, you can still search.
$git rev-list-- all | xargs git grep-F''
For example, suppose you want to search your warehouse for the string "font-size: 52 px;":
$git rev-list-all | xargs git grep-F 'font-size: 52 px;'F3022... 9e12:HtmlTemplate/style.css: font-size: 52 px;E9211... 8244:RR.Web/Content/style/style.css: font-size: 52 px; try these tips
Thank you for reading! This is the end of this article on "what are the tips in using git?". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!
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.