What are the differences between git branch, fork, fetch, merge, rebase and clone?

Git This answer includes GitHub as many folks have asked about that too. Local repositories Git (locally) has a directory (.git) which you commit your files to and this is your ‘local repository’. This is different from systems like SVN where you add and commit to the remote repository immediately. Git stores each version of … Read more

How do I clone a generic list in C#?

If your elements are value types, then you can just do: List<YourType> newList = new List<YourType>(oldList); However, if they are reference types and you want a deep copy (assuming your elements properly implement ICloneable), you could do something like this: List<ICloneable> oldList = new List<ICloneable>(); List<ICloneable> newList = new List<ICloneable>(oldList.Count); oldList.ForEach((item) => { newList.Add((ICloneable)item.Clone()); }); … Read more

How do you make a deep copy of an object?

A safe way is to serialize the object, then deserialize. This ensures everything is a brand new reference. Here’s an article about how to do this efficiently. Caveats: It’s possible for classes to override serialization such that new instances are not created, e.g. for singletons. Also this of course doesn’t work if your classes aren’t … Read more

How do I copy an object in Java?

Create a copy constructor: class DummyBean { private String dummy; public DummyBean(DummyBean another) { this.dummy = another.dummy; // you can access } } Every object has also a clone method which can be used to copy the object, but don’t use it. It’s way too easy to create a class and do improper clone method. … Read more