2
Recently, I had a conflict problem between my local branch impl-springboot4 and the remote branch master. At the time of MERGE via Pull Request, there was conflict where I had to enter the impl-springboot4 branch to resolve.
The conflict was in the archive Usuariodto.java.
Within the branch impl-springboot4, done git pull origin master to update it in order to resolve the conflict. However, other files with new versions coming from origin master have integrated into my branch, about 74 files.
I resolved the conflict in the Usuariodto.java file, commited and gave git push -u origin impl-springboot4, but some files of new versions that came from origin master and did not contain conflict have disappeared from my project. In my commit, only the patch of the conflicting file appears. There’s no information in my commit that I deleted a new origin master file at the time of git pull origin master in my local branch. I’ve done git pull origin master to recover the missing files, but my branch isn’t pulling these files anymore. I remember doing git checkout -- . for all files and only includes the conflicted file.
In git diff inside my branch’s bitbucket, all the new version files my branch received at the time of git pull origin master appear, with the addition, removal, and editing of those files. Deleted files no longer appear on my branch, but they still remain on origin master.
I’ve tried git revert HEAD , git reset to commit to undo this merge commit but I can’t, it’s an error. My fear is that when one merges via Pull Request, these deleted files will also be deleted from the Master remote repository, and as far as I can remember, I didn’t delete any files, but everything indicates that some files have been deleted in my branch and if this is for origin master, it may end up deleting from the remote repository too and this I don’t want to happen.
What should I do? Cancel pull request and open another branch to play my implementation or I can fix it by undoing that last commit with additions/edits/exclusions?
I am very worried about this and I spent about 5 hours trying to fix this situation but without success. I appreciate any guidance. thanks
I’ve had similar problems and managed to solve them in the simplest way: when the user clones a Github project on the computer, always in the directory where the user initializes the repository there is a hidden folder called .git. If you are using the linux shell, try deleting the folder. git that is inside the project and type
clear
in the terminal. You will see that the(master)
will no longer appear in your project, so just initialize the repository and commit again.– pe.Math
it is not recommended to undo commits or even try to edit them, as each commit is an update (version) of your project, when you risk trying to change it you will run serious risks in losing all updates (commits) of your project.
– pe.Math
whatever, usually the Windows command prompt operates by MS-DOS, so I strongly recommend using Git Bash’s Shell Script to perform the operation. As the case is the Github repository, you can use Git Bash in this case.
– pe.Math
By Git Bash, you go to the folder where your cloned repository is, delete the folder
.git
gives aclear
in the terminal to clear the console. When the(master)
appears, it means that that project is no longer a repository, so just typegit init && git add . && git commit "realizando o commit novamente" && git remote add origin "<URL do repositorio>" && git push -u origin master
. Sorry about the joker&&
, I do not want to explain in detail what it serves, but if it is of interest to you I leave here the link for study:– pe.Math
https://stackoverflow.com/questions/4510640/what-is-the-purpose-of-in-a-shell-command
– pe.Math
Very interesting, your explanation. I confess that I don’t feel safe using these commands in git, using only the usual (push, pull, merge, commit, add, checkout --...). I thought of another alternative, see if it’s possible: I thought about doing GIT CHECKOUT MASTER, copying all the files and playing to any non-local repository folder, after GIT CHECKOUT IMPL_SPRINGBOOT4 and paste the files previously copied from the master repository. git will automatically check the files that are the same, the new files and the updated version files. So, commit.
– brunoo
do the alternative that you think is best for you, often it is better to use the usual commands that you know well than to take risks on others that are seen by the internet and that are not very common to use, unless you have specific cases that need to use these other paths, but I advise you to always follow the usual ones as you mentioned.
– pe.Math
It’s possible to work in many ways with Git Hub, but the idea is to keep in mind that when it comes to commit, it refers toif the versions of your current project and if you want to reverse some commit on the platform itself you have the option to click the commit you want to update to the current state of your project, download all of its files and replace them in the current directory of your project and commit tothem again.
– pe.Math
Looking at the situation, I believe that copying the master files as I mentioned earlier and pasting inside the impl_springboot4 branch is the easiest way to do it without using specific git commands. And the big problem is that the commit has already been pushed to 'origin impl_springboot4', and from what I researched it’s not possible to undo this commit because it was already pushed, and I tried to make git revert HEAD ' but git didn’t allow it, and it could be a problem. Therefore, I see that the solution would be the one I described and intend to do today. You think you will solve the problem?
– brunoo
Yeah, just test and see
– pe.Math