开发者

How can I disregard new files added to the git?

开发者 https://www.devze.com 2023-03-24 22:12 出处:网络
I accidentally added many files (test files) which I do not want them to be part of commit. I want to reset the branch back to the head, but I already have few files which I have modified, and which

I accidentally added many files (test files) which I do not want them to be part of commit.

I want to reset the branch back to the head, but I already have few files which I have modified, and which I want them to be part of next commit.

Files that I want to commit and files that I do not want to commit are located in separate folder.

Is there anyway that I can discard newly added开发者_StackOverflow中文版 files, and keep the modified files with git command?

Below is the status that I got.

# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#   new file:   Makefile
#   //and 100 of other files in current directory
#
# Changed but not updated:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#   modified:   ../program.C
#   modified:   ../program.h
#   //and few more files..


git reset <directory> will recursively unstage any files in that directory. Alternately, just git reset to unstage everything, and git add <files> to add back just what you want.


git rm --cached *

This command would remove all files from your index but leaves them in your working tree (i.e. your folder remains unchanged). So then you can just add the files you want with git add


You can use

git reset --soft HEAD^

Your previous commit will fall back. And those files that commit previously will go into your staging directories. Then you can choose which file in staging file to unstage it to working directory.

git reset <path to file>

The above command can make those files that you do not want in that commit fall back to working directory.

For those files that you want to commit again will be still in the staging directory.

then you can make your commit again.

0

精彩评论

暂无评论...
验证码 换一张
取 消