git/list[1] front-page[2] threads[3] people[4] search[5] about
 

fast forward merge overwriting my code

From
AUAndre Ulrich <andre.ulrich@smail.fh-koeln.de>
Date
May 22, 2021, 15:48 UTC
Message-ID
<20210522154815.Horde.rqiNSyIc3CGJECACotWLO1T@webmail.th-koeln.de>
Hello community,

I am new to git, and at the moment I am learning the basics. There are loads of good videos on the internet, but I have one specific question, I haven't found the answer yet:

Let's say I have a .txt file on my master branch. I used
git add .
and
git commit -m "blabla"
so everything is staged and in the history. Now I check out a new branch
git checkout -b testing

and edit the .txt file. I add some new lines at the end, but I also change some of the already existing lines. Then again I add and commit everything. Then I use

git checkout master
and
git merge testing

I would expect git to tell me "hey, wait, you have changed some of the first lines in the .txt file. When you merge, your code on master will be altered". But git just merges everything in. Just imagine this was working code, and changing some of the first lines breaks everything in the following lines. I think I have found out what is the problem: git considers this a fast forward merge (since there were no commits on master between the creation and the merging of the test branch). But this is annoying. I want to be able to choose, what changes I want to keep, when I do the merge (just as in case of a 3way merge, when you can call a graphical merge tool to decide what lines to keep). I know, I could git diff the latest commits hashes of both branches and then fix the file on testing branch accordingly. But those are two separate steps, and I want everything to happen in one convenient step.

Is there any possibility to do so?

Many thanks for any help in advance! Many greetings André Ulrich

-- 
**********************************************************************
**  Fachhochschule Koeln / Cologne University of Applied Sciences
**
**  Andre Ulrich
**  E-Mail: andre.ulrich@smail.fh-koeln.de
**********************************************************************
Next: Philip Oakley
Message 1 of 23 in “fast forward merge overwriting my code”
  1. Andre UlrichMay 22, 2021
  2. Philip OakleyMay 22, 2021
  3. Junio C HamanoMay 23, 2021
  4. Philip OakleyMay 24, 2021
  5. Johannes SixtMay 23, 2021
  6. brian m. carlsonMay 23, 2021
  7. Andre UlrichMay 24, 2021
  8. Bagas SanjayaMay 24, 2021
  9. Philip OakleyMay 24, 2021
  10. Andre UlrichMay 24, 2021
  11. Philip OakleyMay 24, 2021
  12. Philip OakleyMay 25, 2021
  13. David AguilarMay 30, 2021
  14. Philip OakleyMay 30, 2021
  15. Igor DjordjevicMay 24, 2021
  16. Felipe ContrerasMay 26, 2021
  17. Philip OakleyMay 26, 2021
  18. Felipe ContrerasMay 26, 2021
  19. Philip OakleyMay 26, 2021
  20. Felipe ContrerasMay 26, 2021
  21. Philip OakleyMay 27, 2021
  22. Felipe ContrerasMay 27, 2021
  23. Philip OakleyMay 27, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.