开发者

Git hub: I added a file but I want to exclude it from my next commit

开发者 https://www.devze.com 2023-03-22 11:41 出处:网络
I am new to git hub, I added a file by mistake but I dont want it to be there the next time I commit..

I am new to git hub, I added a file by mistake but I dont want it to be there the next time I commit.. How do I view the files that are to be committed next time? and how do I exclude files?

And in general, any recommendations for tutorials for using git hub and its commands (their official开发者_StackOverflow社区 tutorials are horrible)? or any user friendly gui? I have been using cvs and svn for 3 years and I've never suffered that much from a version control system before!!


If you would like to unstage the file, e.g. revert to before you did the

$ git add not_commit.file

simple remove it from the staging area with

$ git rm --cached not_commit.file


http://book.git-scm.com/4_ignoring_files.html

Thats the process for telling git to ignore/exclude a file. Also the documentation isn't too bad.

To view what files will be commited you should run git status before a commit.

Tbh I find git very easy to use if I follow this process....

git status // check what you're about to commit
git add . // add everything (if thats what you want)
git commit -a // commit everything
git pull // make sure you're up to date
git push // push your changes

Hope that helps


You need to remove the file first (from the index only, not from the working directory, in other word not from your disk).
Then you add it to the .gitignore file.

git rm --cached -- local/path/to/theFile
echo local/path/to/theFile > .gitignore
git add .gitignore
git commit -m "ignore now local/path/to/theFile"

From now on, it won't ever be part of your next commits.

git rm man page:

--cached

Use this option to unstage and remove paths only from the index.
Working tree files, whether modified or not, will be left alone.

0

精彩评论

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

关注公众号