Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git: revert all committed files in a directory to master

Tags:

git

git-revert

I have a feature branch feature-1-branch created from master. A lot of time as passed and I created a lot of commits on feature-1-branch.

Now I want to revert commit all changes in a specific directory, lets say src/modules/feature-2 I made in branch feature-1-branch back to the state as they are in master.

Im sure this must be possible in git, just not sure how to do it!?

like image 341
Frank Adrian Avatar asked Apr 21 '17 14:04

Frank Adrian


People also ask

How do you revert a commit to master?

In order to revert the last Git commit, use the “git revert” and specify the commit to be reverted which is “HEAD” for the last commit of your history.

How do I revert a directory in git?

How would I revert just the current directory in Git? Use git checkout instead of reset. git checkout <branchname>~1 -- path/to/directory/you/want/updated should do the trick.

How do you reset committed changes?

Commit the changes, reusing the old commit message. reset copied the old head to . git/ORIG_HEAD ; commit with -c ORIG_HEAD will open an editor, which initially contains the log message from the old commit and allows you to edit it. If you do not need to edit the message, you could use the -C option.


1 Answers

Just checkout src/modules/feature-2 directory from feature-1 branch to origin/master branch.

$ git checkout feature-1-branch
$ git fetch
$ git checkout origin/master src/modules/feature-2/

Now, You have identical src/modules/feature-2 directory in both master and feature-1-branch branch.

like image 199
Sajib Khan Avatar answered Oct 13 '22 01:10

Sajib Khan