I would have gone with her. But she didn't ask me .
I would have gone with her .But she hadn't asked me .
Do we have to use past perfect in this example ? Is there any difference in meanings ?
I agree with James that both sentences are acceptable, but as for the rest of three answer I beg to differ.
I would have gone with her. But she didn't ask me
Uses past simple which is much more common in speech, so English speakers understand it. But it does not fully convey the time order of the events. We assume "she didn't ask me" was earlier because of the "but". But consider this variation: I would have gone with her any time. But she didn't ever ask me. No order of events here.
I would have gone with her. But she hadn't asked me.
This one has past perfect which is a not used as often. But it is very precise about the order of events. It described an event set in the past; at the time, the narrator was ready to "go with her". The "would have" means it did not happen in reality, and the reason comes next - she hadn't asked. "Hadn't" means the non-asking was complete (perfect) at the time, so clearly it refers to an earlier time frame than the narrator is referring to.
In summary, past perfect is perfectly suitable here and may be preferable if the intent is to convey the order of events.
Both sentences are acceptable, but the first is more likely to be used by native English speakers. The two sentences are not quite identical in meaning.
The first sentence is fairly straight forward and essentially says:
She went somewhere without asking me to go with her. If she had asked, I would have gone with her.
The second sentence is more complex. The use of the past perfect makes it feel like the sentence is incomplete, or possibly something is being withheld. The past perfect is usually used to indicate that some action in the past was completed before another action started. This second sentence does not indicate what that second action may have been.
For example, possible additions could be:
I would have gone with her. But she hadn't asked me the first time she went, and I didn't want to intrude later.
I would have gone with her. But she hadn't asked me for anything since we argued.
I would have gone with her. But she hadn't asked me in time for me to cancel my appointment.