First-hand accounts of trench warfare, gas attacks and battles involving horses and machine guns, are contained in nearly 4,000 diaries released online on Thursday to mark the centenary of the 1914-18 world war.

The diaries, digitised by the National Archives in a joint project with the Imperial War Museum, reveal the sheer stoicism and black humour that helped troops – on both sides – survive the slaughter in Belgium and northern France. They include accounts of the battle of Loos in September 1915, a notoriously unsuccessful and bloody offensive in which the British army used poison gas for the first time and suffered more than 60,000 casualties in less than a month.

An intelligence report of the army's 12th division in northern France, dated 10 July 1915, records: "A brown paper kite was found on night 8/9th in front of the right section of our line … covered with German writing, of which the following is a rough translation: 'You can fill your trenches with devils – we Germans fear nothing in the world, and we Germans await victory … Englishmen, how badly you shoot! You will be served as the Russians'."

The message added that while German soldiers had "wine, sausage and meat", the British were "hungry and thirsty".

An intelligence report later that week reflects the eerie nervousness of the soldiers keeping watch at night and hearing every movement in the enemy trenches. "Two cats and a dog are under suspicion as they have been in the habit of crossing our trenches at night: steps are being taken to trap them if possible."

Some of the war diaries are almost swashbuckling in tone. An account of an attack by the Indian army's Mhow Cavalry Brigade, on 1 December 1917 in northern France after promised tanks had failed to arrive, records: "Lieut Broadway had already killed two Germans with the sword when he was treacherously killed by a revolver shot by a German officer who raised one hand in token of surrender keeping the other behind his back. This German officer was immediately killed by a lance thrust from a man following Lieut Broadway."

On the same day, a "patrol galloped up to the trench and crossed it, pretending not to see the Germans who let them go by. They then turned about and galloped back under heavy machine gun fire … Too much cannot be said of the spirit and conduct of all ranks of the Central India Horse throughout the day".

William Spencer, military records specialist at the National Archives said the diaries showed "advances in technology that made it the world's first industrialised war with many mounted troops going into battle at first with swords on horseback and ending the war with machine guns and tanks".

But the diaries also drive home the extent of casualties in battles of attrition where soldiers got nowhere. A record of the battle of Loos, by Colonel S E Hollond, notes: "The preliminary bombardment lasted 4 days. There was practically no reply."

But the British artillery failed to destroy the German defences. Moreover, "the wind was shifty … The gas and smoke never went over the German trenches but came back over our own men and gassed a good many of them".

In their first assault British troops were "wiped out" by heavy machine gun and rifle fire. Out of 800 men and 20 officers of the 5th Camerons (Highlanders) 700 men and 18 officers are described as having been "knocked out". Col Hollond adds: "Yet they reached their objective with the remaining 100 men and 20 officers. This is a feat I think of which the 5th Camerons can be justly proud." The Kings Own Scottish Borderers, meanwhile, lost all their officers "and 3/4 of their men".Three days into the battle, Colonel Murray Threipland of the Welsh Guards recorded that he had "no more sound men at the front". He added: "Either too bad to move, or Germans have got them. We have recovered no officers' bodies; it only meant lives lost to get them, and I refused to allow it."

The diaries include a sketch of dummy figures deployed by British troops in a tactic called "Chinese attacks" after deception techniques developed by Chinese military strategists.

The diaries are available online via the National Archives' first world war 100 portal.