笔者一般在linux上做版本控制。
近期,在windows上使用,发现:
即使没提交到staging area,.gitignore仍然没有起作用。
(base) PS E:\idm下载\test_git> ls
(base) PS E:\idm下载\test_git> echo 1 > 1.sh
(base) PS E:\idm下载\test_git> echo 2 > 2.sh
(base) PS E:\idm下载\test_git> echo 1.sh > .gitignore
(base) PS E:\idm下载\test_git> git status
On branch main
Your branch is ahead of 'origin/main' by 1 commit.
(use "git push" to publish your local commits)
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
deleted: .gitignore
Untracked files:
(use "git add <file>..." to include in what will be committed)
.gitignore
1.sh
2.sh
Make sure your
.gitignore
file usesANSI
orUTF-8
encoding. If it uses something else likeUnicode BOM
, it's possible that Git can't read the file.
以上是Stack Overflow上的一则评论,说明是编码问题。
确实如此。
用vscode修改一下编码,改为utf-8。