git-rm

Remove file from the repository but keep it locally

半腔热情 提交于 2019-11-27 08:55:53
问题 I have a folder which I'd like to remove in my remote repository. I'd like to delete it, but keep the folder in my computer 回答1: git rm --cached -r somedir Will stage the deletion of the directory, but doesn't touch anything on disk. This works also for a file, like: git rm --cached somefile.ext Afterwards you may want to add somedir/ or somefile.ext to your .gitignore file so that git doesn't try to add it back. 回答2: I would just: Move the folder out of your working tree git rm the folder,

How do I git rm a file without deleting it from disk? [duplicate]

若如初见. 提交于 2019-11-27 02:29:35
This question already has an answer here: Remove a file from a Git repository without deleting it from the local filesystem 9 answers The command removes the file in my system. I meant it to remove only the file from Git-repository. How can I remove the file from a Git repository, without removing the file in my system? According to "git help rm", git rm --cached file should do what you want. I tried experimenting with the answers given. My personal finding came out to be: git rm -r --cached . And then git add . This seemed to make my working directory nice and clean. You can put your fileName

Why are there two ways to unstage a file in Git?

和自甴很熟 提交于 2019-11-27 02:19:53
Sometimes git suggests git rm --cached to unstage a file, sometimes git reset HEAD file . When should I use which? EDIT: D:\code\gt2>git init Initialized empty Git repository in D:/code/gt2/.git/ D:\code\gt2>touch a D:\code\gt2>git status # On branch master # # Initial commit # # Untracked files: # (use "git add <file>..." to include in what will be committed) # # a nothing added to commit but untracked files present (use "git add" to track) D:\code\gt2>git add a D:\code\gt2>git status # On branch master # # Initial commit # # Changes to be committed: # (use "git rm --cached <file>..." to

Removing multiple files from a Git repo that have already been deleted from disk

醉酒当歌 提交于 2019-11-27 01:54:44
I have a Git repo that I have deleted four files from using rm ( not git rm ), and my Git status looks like this: # deleted: file1.txt # deleted: file2.txt # deleted: file3.txt # deleted: file4.txt How do I remove these files from Git without having to manually go through and add each file like this: git rm file1 file2 file3 file4 Ideally, I'm looking for something that works in the same way that git add . does, if that's possible. For Git 1.x $ git add -u This tells git to automatically stage tracked files -- including deleting the previously tracked files. For Git 2.0 To stage your whole

“git rm --cached x” vs “git reset head --​ x”?

天涯浪子 提交于 2019-11-26 23:46:03
问题 GitRef.org - Basic: git rm will remove entries from the staging area. This is a bit different from git reset HEAD which "unstages" files. By "unstage" I mean it reverts the staging area to what was there before we started modifying things. git rm on the other hand just kicks the file off the stage entirely, so that it's not included in the next commit snapshot, thereby effectively deleting it. By default, a git rm file will remove the file from the staging area entirely and also off your disk

Why git rm --cached not remove local ever tracked file but others

别来无恙 提交于 2019-11-26 21:57:23
问题 When untrack a file in the git repository, use git rm -r --cached . . This will not remove the ever tracked file in local storage, but when other developers fetch this commit with git pull , the ever tracked file will been removed on their machine storage. You can reproduce it with: save current work. ( Machine A ) git add . git stash save "work position" create a new file and commit it.( Machine A ) echo hello>>file_not_to_track git add . git commit -m "add file file_not_to_track" pull from

Git: list only “untracked” files (also, custom commands)

£可爱£侵袭症+ 提交于 2019-11-26 18:00:33
Is there a way to use a command like git ls-files to show only untracked files? The reason I'm asking is because I use the following command to process all deleted files: git ls-files -d | xargs git rm I'd like something similar for untracked files: git some-command --some-options | xargs git add I was able to find the -o option to git ls-files , but this isn't what I want because it also shows ignored files. I was also able to come up with the following long and ugly command: git status --porcelain | grep '^??' | cut -c4- | xargs git add It seems like there's got to be a better command I can

Git: How to remove file from index without deleting files from any repository

て烟熏妆下的殇ゞ 提交于 2019-11-26 15:00:02
问题 When you use git rm --cached myfile it doesn't delete from the local filesystem, which is the goal. But if you've already versioned and committed the file, pushed it to a central repository, and pulled it into yet another repository before using the command, it will delete the file from that system. Is there a way to just remove the file from versioning without deleting it from any filesystem? Edit: Clarified, I hope. 回答1: I do not think a Git commit can record an intention like “stop

Remove a folder from git tracking

こ雲淡風輕ζ 提交于 2019-11-26 14:57:56
问题 I need to exclude a folder (name uploads) from tracking. I tried to run git rm -r --cached wordpress/wp-content/uploads and after that I added the path to .gitignore /wordpress/wp-content/uploads but when I ran git status they show up as deleted. If I try to commit the changes, the files will be deleted, not only removed from tracking. What am I doing wrong? I have also tried git update-index --assume-unchanged <file> but this seems to untrack only files. But I need to remove an entire folder

Why are there two ways to unstage a file in Git?

半世苍凉 提交于 2019-11-26 12:33:38
问题 Sometimes git suggests git rm --cached to unstage a file, sometimes git reset HEAD file . When should I use which? EDIT: D:\\code\\gt2>git init Initialized empty Git repository in D:/code/gt2/.git/ D:\\code\\gt2>touch a D:\\code\\gt2>git status # On branch master # # Initial commit # # Untracked files: # (use \"git add <file>...\" to include in what will be committed) # # a nothing added to commit but untracked files present (use \"git add\" to track) D:\\code\\gt2>git add a D:\\code\\gt2>git