Wednesday, May 1, 2024
HomeJavaScriptTips on how to safely take away untracked information from Git repos

Tips on how to safely take away untracked information from Git repos


The wonderful thing about Git is that the majority actions are reversible! However there’s one command that is not, and it may trigger actual complications — git clear.


git clear .

The clear command removes untracked information out of your Git working tree, and whereas that is generally precisely what you need, it’s best to actually run the command with warning.

You are in all probability annoyed whenever you need to begin over, however you ought to be positive you need to throw away every part. Some information would possibly nonetheless be priceless. Should you run git clear, they’re gone — finish of story.

By default, Git is not going to assist you to clear up a repository except you may have clear.requireForce set to false. However you know the way it’s: an harmless -f is rapidly added.

I discovered right now that git clear (and different instructions) assist a --dry-run possibility.

git clear --dry-run .
Would take away not-important.js
Would take away untracked-but-very-important.js

If you’d like a shorter command line possibility, use the very intuitive (not!) -n argument.

git clear -n .
Would take away not-important.js
Would take away untracked-but-very-important.js

The command prints out what it will take away with out doing any injury. Helpful! It additionally comes with a helpful interactive mode to deal with many untracked information.

git clear -i
Would take away the next gadgets:
  not-important.js   untracked-but-very-important.js
  
*** Instructions ***
  1: clear   2: filter by sample   3: choose by numbers   4: ask every   5: give up   6: assist
What now> 4
Take away not-important.js [y/N]? y
Take away untracked-but-very-important.js [y/N]? N
Eradicating not-important.js

You’ll be able to select between sample matching or checking every file one after the other within the interactive mode. Good one, Git! 💪

However what about different Git instructions? Many of the different dry runs do not appear very thrilling to me as a result of, as stated, many of the Git operations are reversible. However one which I might see come in useful is a git distant prune dry run to keep away from eradicating distant branches. However that is about it. 🤷‍♂️

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments