Updated:

1. Hide enchantments (1.21.5+)

/give @s minecraft:diamond_sword[enchantments={sharpness:5},tooltip_display={hidden_components:["enchantments"]}]

List the components to hide in hidden_components. The enchantments still work; they just no longer show.

2. Hide several lines

/give @s minecraft:diamond_sword[enchantments={sharpness:5},unbreakable={},tooltip_display={hidden_components:["enchantments","unbreakable","attribute_modifiers"]}]

Other useful names: can_break, can_place_on and dyed_color. attribute_modifiers also hides the default attack damage and speed lines.

3. Hide the whole tooltip

/give @s minecraft:diamond[tooltip_display={hide_tooltip:true}]

Nothing shows on hover, not even the name. Good for mystery items.

4. Remove or add the glint

/give @s minecraft:diamond_sword[enchantments={sharpness:5},enchantment_glint_override=false]
/give @s minecraft:stick[enchantment_glint_override=true]

Works on 1.20.5 and later.

5. 1.20.5 to 1.21.4

/give @s minecraft:diamond_sword[enchantments={levels:{sharpness:5},show_in_tooltip:false},unbreakable={show_in_tooltip:false}]
/give @s minecraft:diamond[hide_tooltip={}]

Each component took show_in_tooltip:false; other details were hidden with hide_additional_tooltip={}.

6. 1.20.4 and older

/give @s minecraft:diamond_sword{Enchantments:[{id:"minecraft:sharpness",lvl:5s}],HideFlags:1}

Add up the flags: 1 enchantments, 2 attributes, 4 Unbreakable, 8 CanDestroy, 16 CanPlaceOn. See NBT vs components.

Troubleshooting

Check your command

The Command Error Doctor checks common syntax mistakes in your browser.