Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 491849
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T02:03:10+00:00 2026-05-13T02:03:10+00:00

Say I have function X in file A, and I wanted to move that

  • 0

Say I have function X in file A, and I wanted to move that function to file B. In the meantime, somebody else made changes to function X in file A.

Does git do anything special when merging those two changes? Would it recognize the same function was moved to file B and apply the changes there? Or would we end up losing the changes or having two copies of the same function in file A and B?

Most of the articles I found about moving code in git refer mostly to renaming whole files and not blocks of code inside files. The closest I found is a blurb from Linus at kerneltrap:

And when using git, the whole ‘keep
code movement separate from changes’
has an even more fundamental reason:
git can track code movement (again,
whether moving a whole file or just a
function between files), and doing a
‘git blame -C’ will actually follow
code movement between files. It does
that by similarity analysis, but it
does mean that if you both move the
code and change it at the same time,
git cannot see that ‘oh, that function
came originally from that other file’,
and now you get worse annotations
about where code actually originated.

So it seems like git will recognize that the code was moved somewhere else, but doesn’t really say what happens during a merge.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T02:03:11+00:00Added an answer on May 13, 2026 at 2:03 am

    No, git won’t do this level of change. It will notice when you move an entire file; so, for example, if you moved the file, deleted everything else in it, then it might stand a chance of picking up the changes. But it doesn’t do a change on a per-subfile or any kind of refactoring.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say you have a function that returns a date: Date myFunc(paramA, paramB){ //conditionally
Say I have a Python function that returns multiple values in a tuple: def
Say I have a file Foo.php: <?php interface ICommand { function doSomething(); } class
I have a function, say f(args) , that is being called from many places
Let's say I have a page that refers to a .js file. In that
Say I have the function shoutout inside my .profile file. When I run shoutout
Let say I have this code in a JS file called plus2.js: function plus2(n){
Let's say I have something like this in a file named main.js : function
Let's say I have a namespace like that: var myNamespace = { foo: function()
Say I have a C function which takes a variable number of arguments: How

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.