Where can I find documentations on how to resolve a git conflict properly?
Today I did a git push --force, then I had to create a branch out of the old code, but other times I had to save the files I worked on, delete the local repository, git clone again, then reapply my fixes. I want to at least have a bookmark on how to fix things in the future.
Yes, I've heard about VSCode plugins, that supposed to help. But no, I don't want to use a glorified webpage to do coding, regardless if it's directly tied to Micro$lop, or some of the slop was removed by 3rd parties. I tried KATE once, I cannot go back to some sluggish webpage, which only argument for use at the moment is "but it has plugins".
If you don't know how to resolve conflicts, you should not be using
--forceor rebase. It can mess your code even more than conflicts.As for resolving conflicts, it's pretty straightforward, you have markers in your code for your local changes vs pulled code, just fix it up ro what you think thr code should be. Make sure you resolve all conflicts then stage and commit the changes.
Since no one is answering directly, here’s the steps to follow and you can go from here to find the specific commands. If you want to get back to a specific point in the history of the remote repo as a means to undo a mistake, and then continue from that point with any changes then usually you want to do this in a non-destructive way. ie. accept you screwed up and don’t cover it up.
There are many ways but this is the way that works.
The replies so far aren’t wrong, but there’s probably a more fundamental issue here.
Your risk of conflicts increases as you add more clones, add more working copies, add more collaborators. It usually decreases if folks regularly push their changes, regularly pull others’ changes, and get out of each others’ way by judiciously using branches and merging the branches back in when the work necessitating that branch is completed.
We use these materials to teach scientists and engineers about Git, and the specific section on resolving conflicts is here. We don’t cover branching since we only have a couple hours total.
The workflow we try to drill into the students starts out as:
git addand/orgit rmto set what will be committed.git committo commit those changes.Nobody ever gets conflicts at this stage because there’s only one working copy and one repository per student. No remotes, no collaborators, no extra clones.
Then we bring in remotes. This changes the workflow to:
Still no conflicts as long as there’s only one working copy, one local repository, and one remote that’s basically a push-only copy of the local repo.
Then we add a collaborator and the workflow changes to:
Still no conflicts as long as only one person at a time is working, and as long as each person does all the steps, including the pull.
The conflicts section starts with one or more collaborators omitting the pull step, making concurrent changes to the same part of a file, and pushing.
That’s all that’s required to cause a conflict, and it gets technically resolved by the later pusher editing the files to remove the conflict punctuation, making a new local commit with those changes, and pushing. Git itself doesn’t care if it’s the “correct” set of changes, only that the conflict punctuation is removed.
The post was getting long enough already, but see the end of the conflicts section for several things you can do to reduce the likelihood of conflicts. Some are technical, others are more about communication and management.
Perhaps these may help you:
https://learngitbranching.js.org/
https://gitmastery.me/
https://onlywei.github.io/explain-git-with-d3/
Is the official git documentation insufficient?
I want to learn about that specific issue rather than spending months with learning less often used features of a software. People generally don't master all the available functions of a software before touching said software. Maybe in the sixties-seventies, but not anymore. And there's also the issue of people forgetting stuff, which will happen when my main interaction with git is pull and push.
You do realize that you don’t have to read a documentation from beginning to end, don’t you? But for that specific feature you need and don’t know how to use—RTFM!
Check out the Atlassian docs for any git related topics or commands as they are usually easier to make sense of with example situations and explanations beyond describing just the feature or functionality.
I always like the website https://ohshitgit.com/ for all kinds of common git issues.
Disclaimer: it's been a while since I've used git.
You'll be unable to push if the remote branch has diverged since you pulled because someone else has pushed changes different from your own.
One way to resolve this is to run
git pull. If your commits have made changes to a file and the diverging commits have made changes to the same file, then you'll have a conflict and git will put your local repo into a special merge conflict state. Your working files involved in the conflict will be automatically changed to include the differing changes, delimited by<<<,===, and>>>characters. You'll have the option to abort thepullor edit the files,git addthem, and thengit commitwhich completes the pull. You can then push.git pullwill dogit fetchto update your copy of the remote branch, followed by agit merge. The documentation for resolving merge conflicts is contained in the git-merge man page:git help merge, particularly in the sections entitled "Pre-merge checks", "How conflicts are presented", and "How to resolve conflicts". Side note: the man page will open in the system pager, in which typing/conflictand the keysnandNwill step through each occurrence of the word "conflict". Oh, you can even read it in glorious PDF.^[https://manpage.me/index.cgi?apropos=0&q=git-merge&sektion=0&manpath=Debian+8.1.0&arch=default&format=pdf]Running
git pullwhen you have uncommited files may be a different story entirely. Best to not do that. You can check whether your working files are clean withgit status. It seems like the "proper" way to deal with this situation, if you must, is withgit stash. That supposedly can be used to save your uncommited changes, cleanup your worktree to prepare it for a pull, and reapply the saved changes after.I recommend sections in the free Pro Git book if your want something more pedagogical than the man pages.
As others have said, you need to at least learn the basics about git such as branches, remotes and merging. No plugin or tool will help you avoid that. When you feel very comfortable with the basics, I recommend learning how to rebase instead of merging for conflict resolution.
Second this.
https://www.atlassian.com/git/tutorials/merging-vs-rebasing
You should also set it in your got config to pull.rebase true to avoid fast forwarding and other issues without being aware of how changes on main actually affect your branch changes and resolving them yourself so that your changes make actual sense when going into main.
What are you talking about? If you're having git problems use whatever editor you want to fix the conflicts then delete the conflict markers and save the document. If you want nice syntax highlighting, find an editor that does that. If you don't want an editor that does that, then don't and continue to use nano or Ed or whatever.
Also, why are you git pushing with force. There's generally no reason to be using force unless you've already fucked the repo. Default to not using force, and if you're pushing a rebase use force-with-lease. Any LLM is great for git shit cause there's so many people that suck at it that it's well represented in the training data
https://github.com/k88hudson/git-flight-rules/blob/master/README.md
That word does get an S. It's like 'happy'; and like 'e-mail' if people passed elementary school.