Reputation: 55
I am relatively new to git and just committed some extra files and also added something which causes an error to a file.
I want to remove the extra files as well as push the edited file . How do I do that ?
P.S - A contributor has asked me to do it using --force
Upvotes: 0
Views: 1148
Reputation:
To remove unwanted files from your working directory and your working tree:
git rm <file1> <file2>...
git add . && git commit --amend --no-edit
The --amend
option modifies the commit pointed to by HEAD
instead of creating a new commit, while the --no-edit
option allows you to amend the commit without altering its commit message.
To remove directories, use the recursive option -r
, and follow it by the directory names you want to remove. You might want to use it with the --dry-run
option (shorthand: -n
) to see what files would be deleted.
Upvotes: 0
Reputation: 142164
Its pretty simple.
Change the file system the way you want it to be by editing and adding the new content.
Once the content is ready add it to stage and commit it.
Short version:
// If you only wish to remove files from the repository
git rm --cached <file to remove>
// or if you only wish to remove files form disk & repo
git rm <file to remove>
Detailed version:
.. Current commited content
.. edit any file or remove any file
// Add the changes to the stage area.
// Any new change here will be added to the latest commit later on
// with the commit --amend flag
git add <files to be changed>
// if you wish to remove the extra files - remove them from stage
// and commit the change
git rm --cached <file to remove>
// Update the latest commit and add the new changes made to the index
git commit --ammend
// Update remote server with the new changes
git push -f origin <branch>
Upvotes: 0
Reputation: 2509
Step 1:
Remove the unwanted files from your disk. Edit the file by fixing what you need to fix.
Step 2:
Execute those commands:
git add *
git commit -m "some message"
git push origin master
If you are working on other branch just change master with your branch's name.
Upvotes: 1