Source control and Git utilization
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I am working on a private Git branch called and I usually commit and push changes of my code directly on this branch. I am in a situation now where I have to merge my branch into the 'master' branch, basically deprecating the previous version of 'master' and making my private branch the new baseline. I see the buttons 'Switch' and 'Merge' within the 'Source Control' --> 'Branches' environment but I am afraid to make a mistake and merge the master branch contents into my personal branch, thus deleting all the latest progress I made on it. Can anyone advise on how to complete this process, essentially merging my private branch into 'master' thus deprecating the former contents of the 'master' branch? Is there also a way to revert such commits in case a mistake is, indeed, made?
1 comentario
Guilherme
el 17 de Oct. de 2022
According to this link: https://www.mathworks.com/help/matlab/matlab_prog/branch-and-merge-with-git.html it seems that what you're trying to do is to merge your branch to the main one. As the article suggests, you can choose how to keep your version of files and how to deal with conflicts. While switching would just put you to another branch with their specific code.
It also seems possible to revert to a specific git state: https://www.mathworks.com/help/simulink/ug/revert-changes.html
Respuestas (1)
Divyam
el 14 de Oct. de 2024
If the GUI appears confusing when trying to perform the merge, you can use the command line alternative for Git and enter the following commands in the terminal.
The first step is to make sure that all your changes are committed in your private branch and created backups for your private branch.
After you have committed the changes, switch to the master branch using the following commands
git checkout master
To merge your private branch into master
git merge <your-private-branch>
Resolve the merge conflicts which arise and then push the changes to your repository
git push origin master
If you wish to revert the changes, use git log to find the commit hash of your merge commit
git log
Revert the merge commit
git revert -m 1 <merge_commit_hash>
Push the revert
git push origin master
This will undo your changes and revert the changes made to your master branch.
As @Guilherme suggested, if you wish to use the GUI provided by MathWorks, you can refer to the documentation links provided in his comment to easily perform your merge.
0 comentarios
Ver también
Categorías
Más información sobre Source Control en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!