undoing changes to bashrc from terminal

后端 未结 5 1432
半阙折子戏
半阙折子戏 2021-01-12 11:03

Unfortunately I just overwrote my .bashrc with

echo \"command\" > ~/.bashrc

as opposed to append

5条回答
  •  不思量自难忘°
    2021-01-12 12:09

    For the future you may consider using a version control system such as git or hg in order to save previous versions of files such as ~/.bashrc. Then if you happen to do a > rather than >> in the future you should be able to recover the file back to the point the last time you commited it to the version control.

    An example of how to set this up for git would be:

    cd ~
    git init
    git add ~/.bashrc
    git commit -m "Added .bashrc to version control"
    # Time goes by...
    echo "export FOO=bar" >> ~/.bashrc # Added a new line
    git commit -am "Added FOO to .bashrc"
    # Time goes by...
    echo "export SHEEP=lambs" > ~/.bashrc # Eeek! We've overwritten our file
    # Version control to the rescue
    git checkout ~/.bashrc # file is restored
    echo "export SHEEP=lambs" >> ~/.bashrc # Done correctly this time!
    git commit -am "Added SHEEP to .bashrc"
    

提交回复
热议问题