Git: the file on the branch is no longer needed on the branch

In my branch_a branch there is a file (file_a.txt) that should NOT differ from a file with similar names to master. I would like to change the branch so that this modified file is removed from the branch, that is, so that the immutable file from "master" is again present, and not the changed branch of this file. What I'm trying to avoid is to maintain this file, which should never have been modified.

I thought that first would be git - reset. Then I thought that maybe I need a "git -rm" file, but that will not leave me with the file. I need to remove it from the branch, so this is not another version of that on the "master". What is the best practice in this situation?

+4
source share
1 answer

I assume that you just need to reset return this file to the version on master , and not erase the change history, fix it? The former is easy, the latter requires modification of the story and should not be done lightly (especially if you clicked a branch outside your local repo).

In reset, the contents of the file foo/bar/baz.txt will return to the state that it has on master , just check your branch and run

 git checkout master -- foo/bar/baz.txt 

This will capture the file from the wizard, write it to your working copy and place it in the index. Now you can just git commit , and your file will now match that on master .

+4
source

Source: https://habr.com/ru/post/1432817/


All Articles