-1

I am learning git, and I am a beginner. I have just finished CodeCademy's Git course (https://www.codecademy.com/learn/learn-git), so I wanted to try something on my computer. I initialized a new git repository. Then I changed the a.txt file, but there appeared a new file, 'a.txt~', which I found is a backup file. After adding and committing, the file is still there. I am still a total beginner in GIT. I have no idea what is going on. But I guess this shouldn't be happening. What should I do to prevent this in the future? I don't think deleting it all the time is a good idea.

enter image description here

adler
  • 61
  • 8
  • 1
    **DO NOT post images of code, data, error messages, etc.** - copy or type the text into the question. [ask] – Rob Oct 23 '21 at 09:30

1 Answers1

1

The backup file is created by the editor, not git. It is just another file. In your figure, you created an empty repository and there are three files in the working directory (a.txt, b.txt, README.txt). You edited a.txt with gedit, and now there are 4 files (a.txt, a.txt~, b.txt, README.txt). You added a.txt and committed it to the repository. The status now says that there are three other files that it doesn't know about, because they haven't been added to the repository.

codegen
  • 118
  • 5
  • Can I hide the 'a.txt~' somehow? Or is it a common practice for Linux users to have two versions of each file? – adler Oct 23 '21 at 03:10
  • If you don't care about the backup file, simply remove it. You can also change gedit preferences not to save a backup file in the first place. (edit->preferences->editor) – codegen Oct 23 '21 at 03:16
  • Okay, thank you very much! If I use Git, then is it worth it to use the backup file from Gedit? – adler Oct 23 '21 at 03:21
  • Also, not all editors on Linux create backup files when editing. gedit is one of the ones that default to creating a backup file. – codegen Oct 23 '21 at 03:22
  • I would say I don't, except that I don't use an editor that creates a backup file. If I was using gedit, I would turn backup files off. One of the things about git, is that it keeps previous versions of files in the repository. – codegen Oct 23 '21 at 03:23