git clean

Viewing 1 post (of 1 total)
  • Author
    Posts
  • #3401 Reply
    Humble
    Keymaster

    Most of the times, we want to remove references to the ‘untracked files’ in the working directory.

    For ex:

    hchiramm@localhost libgfapi-python]$ git status
    # On branch master
    # Untracked files:
    #   (use "git add ..." to include in what will be committed)
    #
    #	.idea/
    #	doc/markdown/.dev_guide.md.swp
    #	libgfapi-python-1.0.0.tar.gz
    #	libgfapi-python.spec
    #	libgfapi.egg-info/
    #	libgfapi/
    #	test/unit/results.html
    nothing added to commit but untracked files present (use "git add" to track)
    
    
    The easiest way of cleaning the 'untracked files/directories' are by 'git clean' command. BUT, before you execute the command make sure you are not deleting the right files. 
    
    The best option is executing   a 'dry-run' ( -n or --dry-run option)  on the same before doing the actions. 
    
    For ex:
    
    [hchiramm@localhost libgfapi-python]$ git clean -n
    Would remove doc/markdown/.dev_guide.md.swp
    Would remove libgfapi-python-1.0.0.tar.gz
    Would remove libgfapi-python.spec
    Would remove test/unit/results.html
    
    
    To remove directories you can make use of "-d" option. 
    
    
    [hchiramm@localhost libgfapi-python]# git clean -f -d
    Removing doc/markdown/.dev_guide.md.swp
    Removing libgfapi-python-1.0.0.tar.gz
    Removing libgfapi-python.spec
    Removing test/unit/results.html
    Removing libgfapi.egg-info/
    Removing libgfapi/
    [hchiramm@localhost libgfapi-python]
    
    Now my directory is "CLEAN"
    
    
    [hchiramm@localhost libgfapi-python]# git status
    # On branch master
    nothing to commit, working directory clean
    [hchiramm@localhost libgfapi-python]# 
    

Viewing 1 post (of 1 total)
Reply To: git clean
Your information: