The word sheji 社稷 was a joint reference to the spirits of the soil (tushen 土神) and the spirits of grain (gushen 穀神), in personalized form the Goddess of the Earth (Hou Tu 后土) and the Lord of Millet (Hou Ji 后稷), also called the "rectifyer of fields" (tianzheng 田正). Both deities or groups of spirits were regularly offered sacrifices in ancient China, and the term sheji can thus be called the "state altars".
The sacrifices for these deities were so important that the word sheji also referred to the state as a whole. Defeat in war would "endanger the state altars" (wei sheji 危社稷). According to the chapter Ganshi 甘誓 in the Confucian Classic Shangshu 尚書 "Book of Documents", victory was reported to the ancestral altars, and defeat to the spirits of soil and grain. The philosopher Meng Ke 孟軻 (Mengzi 孟子, ch. Jinxin 盡心 B) even said that the state altars were more important than the well-being of the ruler himself (even if the welfare of the populace stood in the first place).
The Later Han-period 後漢 (25-220 CE) encyclopaedia Baihu tongyi 白虎通義 (chapter Sheji 社稷) explains that the aim of the sacrifices was to seek for further blessings and to thank for past gifts by the deities (qiu fu bao gong 求福報功).
According to legend, Emperor Zhuan Xu 顓頊 had been the first who had delivered sacrifices to the spirits of soil and grain. At that time, the spirit of the soil was called Gou Long 句龍 (in mythology a son of Gong Gong 共工), and that of grain was called Zhu 柱 (a son of Lie Shan 烈山 or Li Shan 厲山). The Zhou dynasty 周 (11th cent.-221 BCE) exchanged the latter with Qi 弃, who was the dynastic ancestor.
The kings of the Zhou dynasty had three altars for the spirits of soil and grain. The Grand Altar of Soil (taishe 太社) was located west of the Storehouse Gate (Kumen 庫門), the Royal Altar of Soil (wangshe 王社, dishe 帝社) inmidst the royal domain (jitian 籍田), and the Minor Altar of Soil (haoshe 毫社) outside the Temple Gate (miaomen 廟門). The first served for the offerings of the nobility and the populace, the second for those of the royal house, and the last for the descendants of nobles who had lost their territories. The regional rulers (zhuhou 諸侯) themselves had domain altars of soil (houshe 侯社) in their own territories, as well as public altars (guoshe 國社). Even Grand Masters (dafu 大夫) had soil-and-grain altars for themselves, called "province" altars (zhoushe 州社) or community altars (lishe 里社).
Each altar consisted of two parts, namely the soil altar (shetan 社壇) in the east, and the grain altar (jitan 稷壇) in the west. The direction of the offerings was towards the north, as usual. The royal altar had the shape of a pentagon, corresponding to the number of the Five Mythological Emperors, and each corner was given that colour which corresponded to the emperors (green, red, yellow, white, and black). The altars of the regional rulers had just the colour of the region in which they were built. Along with the altars, the sacrificial spot was decorated by one/several (?) pine trees during the Xia period 夏 (21th-17th cent. BCE), firs (bo 柏) during the Shang, and chestnut trees during the Zhou period. The trees were later replaced by a wooden board.
Because the unified empire did not include regional states, the emperors of the Han dynasty 漢 (206 BCE-220 CE) ordered to build local community altars (gongshe 公社), and allowed state officials to have their own soil-and-grain altars.
With the foundation of a new dynasty, the grain altars were exchanged, as happened after the demise of the Qin dynasty 秦 (221-206 BCE) and the creation of the Han dynasty. The latter first built an altar for the Goddess of the Earth, along with an altar for Yu the Great 大禹. Only as late as the year 3 CE, the latter was replaced by an altar for the Lord of Millet, as the book Huangfu santu 三輔黃圖 reported. The altars were located in the southwestern suburbs of Chang'an 長安 (today's Xi'an 西安, Shaanxi), as prescribed in the chapter Kaogongji 考工記 of the ritual Classic Zhouli. Cai Yong's 蔡邕 (132-192) short handbook Duduan 獨斷 gives the size of the altar as a square of 5 zhang 丈 of length (see weights and measures). Those of the regional rulers were only half as long. Archaeologists discovered the remains of such an altar in Xi'an. The altars did not have a building, but were just surrounded by a wall. The sacrificial objects were a cow and a sheep (tailao 太牢). The spirits (shenzhu 神主) were symbolized by a bell-shaped stone.
During the Tang period 唐 (618-907), the gods of soil and grain were called dishe 帝社 and diji 帝稷, and the sacrifice was called the "central offerings" (zhongji 中祀). The Song dynasty 宋 (960-1279) decided to have soil-and-grain altars built in every prefecture and district. The sacrificial animals were reduced to a sheep (shaolao 少牢). Rites were preceded by a three-day fasting and accompanied by music and chants.
From the Ming period 明 (1368-1644) on, the sacrifices to the spirits of soil and grain were combined with those of the dynastic ancestors, and the altar was reduced to one single entity. The ancestral altar was then still, as usual, located east of the soil-and-grain altar.
In the Former Han period 前漢 (206 BCE-8 CE), the sacrifices were carried out in the second and tenth lunar months, in the Later Han in the second, eighth, and twelvth lunar months.
The grain altar (shejitan 社稷壇) of the Ming and Qing 清 (1644-1911) dynasties was located west of the Upright Gate (Duanmen 端門) in the entrance parts of the Imperial City (Zijincheng 紫禁城), which is today inside Zhongshan Park 中山公園 of Beijing. The sacrifices were delivered by the emperor twice a year, once in the second lunar month of spring, and once in the second month of autumn (the eighth lunar month). Sacrifices to the soil and grain spirits were also carried out by common people.