![]() ![]() Stash only the changes that are currently staged. Here you can find how to stash only unstaged changes. different base url, ip or port setting) so if you're using git rm -cached anyone who pulls your branch will have to manually re-create the config, or you can send them yours and they can re-edit it back to their ip settings (etc.), because the delete only effects people pulling your branch from the remote.Create the alias for this command: git config -global alias.stashs 'stash push -S'. This last difference is important for projects which include a config file where each developer on the team has a different config (i.e. After running git rm -cached and push your branch to the remote, anyone pulling your branch from the remote will get the file ACTUALLY deleted from their folder, even though in your local working set the file just becomes untracked (i.e.Īnd there's one more important difference: It's unstaged untill it gets added again with git add. git rm -cached will unstage the file for future commits also.git reset HEAD unstages the file in the current commit.These 2 commands have several subtle differences if the file in question is already in the repo and under version control (previously committed etc.): which works for all three types of change Now, git status says: (use "git restore -staged. Update git 2.23.0: From time to time, the commands change. Git reset HEAD (without -q) gives a warning about the modified file and its exit code is 1 which will be considered as an error in a script.Įdit: git checkout HEAD to-be-modified to-be-removed also works for unstaging, but removes the change completely from the workspace No changes added to commit (use "git add" and/or "git commit -a") " to discard changes in working directory) Me$ git reset -q HEAD to-be-added to-be-removed to-be-modified This thread is a bit old, but I still want to add a little demonstration since it is still not an intuitive problem: me$ git status ( update: I finally took the time to summarize the usage of git reset in a tldr page, so now I have a better mental model of how it works, and a quick reference for when I forget some detail.) ** I was scared for an embarrassingly long time to use the git reset command because of its name - and still today I often look up the syntax to make sure I don't screw up. In the context of this question, of a file just added and not committed yet, there's nothing to worry about. * Keep in mind the caveat mentions in his answer, regarding git rm -cached of a file that was previously committed to the repository. ![]() you're unstaging a file that you had just git added for the first time), then the two commands have the same effect, hence the appearance of these being "two ways of doing something". If the file wasn't in revision control before (i.e. git reset HEAD unstages any modifications made to the file since the last commit (but doesn't revert them in the filesystem, contrary to what the command name might suggest**).git rm -cached makes git stop tracking the file completely (leaving it in the filesystem, unlike plain git rm*).To the question of Why are there 2 ways to unstage a file in git? - there is never really only one way to do anything in git. ![]() In this aspect git reset HEAD file and git rm -cached are same, but they are not same ( as explained in the case of files already in the repo) In the case of unversioned file, it is going to unstage the entire file as the file was not there in the HEAD. Git reset HEAD file ( which by default is using the -mixed flag) is different in that in the case where the file is already in the repo, it replaces the index version of the file with the one from repo (HEAD), effectively unstaging the modifications to it. Basically, after the commit, you would have unversioned the file and kept a local copy. In the case where the file is already in the repo, git rm -cached will remove the file from the index, leaving it in the working directory and a commit will now remove it from the repo as well. Git rm -cached is used to remove a file from the index. Nothing added to commit but untracked files present (use "git add" to track)Ġ files changed, 0 insertions(+), 0 deletions(-) Initialized empty Git repository in D:/code/gt2/.git/ When should I use which? D:\code\gt2>git init Sometimes git suggests git rm -cached to unstage a file, sometimes git reset HEAD file.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |