Re: fast forward merge overwriting my code

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 22/05/2021 16:48, Andre Ulrich wrote:
>
> 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).

maybe `git merge --no-ff testing` for use of a command line option

or setup your .gitconfig e.g. `git config --global merge.ff no`,
but also `git config --global pull.ff yes` if you are using `git pull`
(=fetch + merge)

As always, check the manual to ensure understanding.

> 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
Philip



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux